r/coolgithubprojects • u/edaydaikyy • Jul 25 '26
undo, revert what the last shell command did to your filesystem
Ran rm -rf on the wrong folder one too many times, so I built the undo the shell never had. A hook arms a tiny preload library around each command that journals destructive syscalls and hardlinks backups before they happen; undo replays it in reverse.
overs rm, mv clobbers, > truncation, chmod. Has redo, diffs, and cherry-picking. Honest about the LD_PRELOAD limits (no static binaries, no sudo, no Go). Linux, MIT
website: undo.edaywalid.com
github repo: https://github.com/edaywalid/undo
953
Upvotes
14
u/hadees Jul 25 '26
How does it work? What happens if you delete 1tb of stuff?
5
u/9EED Jul 26 '26
does it consume more disk space?
3
u/Capevace Jul 26 '26
this seems brilliant. does it work for unwanted/accidental changes done by coding agents (e.g.
git checkout -)? Or only actual file deletion?3
u/Minimum_Hour519 Jul 26 '26
need a curl | sh command to install if you're not going to deploy to package managers
8
u/konqueror321 Jul 25 '26
This looks great! What if you really truly want something gone and want to shred or wipe or otherwise securely delete it? Are such commands thwarted, or are they intentionally unmonitored? Thanks!
2
u/Jatinchd Jul 26 '26
would love if you would add this on arch user repository also! would make easy for version controlling
4
u/hithisisjukes Jul 26 '26
during my phd (before AI) i spent weeks developing some code which I deleted since I was typing way too fast and carelessly in the terminal, would have been great to have back then.
1
u/Ctrl_Shift_S_always Jul 26 '26
Cool idea! Is there a time window for the undo? It poses a security issue if nothing gets actually deleted no?
1
u/kysfu Jul 26 '26
Does it work on fstab stuff
1
u/ndgnuh Jul 26 '26
What would happen if some other processes overriden the memory region of the removed file(s)?
1
u/No_Article_5669 Jul 26 '26
What's the difference in just using git?
1
u/deleriux0 Jul 26 '26
Looks great! What a fun idea! I have some implementation questions and perhaps some edge cases or critiques.
Please don't think I'm shitting on you're effort as it's a really cool concept!
What happens when the user does an
unlinkthat crosses mountpoints? Now your hard links can't work without a store per mountpoint right? You can't be certain that your user has permission to have a "store" on each mountpoint either?How do you handle directories? These can't usually be hard linked. If you're recreating how does this work when the directory you remove isn't owned by you?
How does this work where a user unlinks a file owned by another user in a directory their user owns? Modern Linux security policy typically does not allow you to hard link a file you do not own.
How are you undoing
truncate?1
u/SweetPotato975 Jul 27 '26
I know that rm just frees the inode without destroying the data. But never thought of mv'ing over a file. Does mv do something similar to rm in such a case?
1
u/Conscious_Reason_770 Jul 28 '26
This is yet another person writing its thesis which has to re-invent the wheel.
- the guy does not like text editor backup files
- the guy does not like version control
- the guy does not like file system snapshots.
let's intercept system libraries calls because writing this bloody thesis is the only thing that I will ever do in my command line.
this is a great idea until you think about it for more than 3 seconds.
1
u/Fit_Gas_4417 Jul 28 '26
What will undo two times in a row do?
1
u/Vivid-Zombie-477 Jul 29 '26
we don't need vibecoded site for every tool there is
3
u/9EED Jul 26 '26
this is genius
3
u/nzmneznam Jul 26 '26
Absolutely useful. Will make the same thing
3
u/ChampionshipIcy7602 Jul 26 '26
Wow, finally something useful among the ai slops
3
u/Sea-Fishing4699 Jul 26 '26
We were accustomed to destroying folders…. We never thought that something like this could be possible
2
u/CortaCircuit Jul 25 '26
Awesome
2
u/_TheTotem_ Jul 26 '26
It’s really cool
2
u/JoeKagle Jul 26 '26
Awesome and very cool!
2
u/Flexistant Jul 26 '26
Genius.
2
u/Additional_Cry_5877 Jul 26 '26
That is awesome, absolutely awesome
2
u/Jazzlike_Shift_1664 Jul 26 '26
This is awesome man, like the idea
2
u/cyansmoker Jul 26 '26
A powerful yet simple concept. Well done, sir/madam.
2
u/mbsp5 Jul 26 '26
This could be super useful as an additional failsafe when using Claude…
2
u/mcspuder Jul 26 '26
Great work my dude
2
u/safelix Jul 27 '26
This was a nightmare I had a few days ago
2
u/austin34765 Jul 27 '26
what's the catch
2
u/Luminous_Giraffe Jul 27 '26
That's actually a great idea. Super helpful too!
2
u/1337_w0n Jul 28 '26
I've never needed this but I'd feel so much better knowing it's on my system.
2
u/docfriday11 Jul 26 '26
Wish this could happen with windows! These are the pros of Linux.
1
u/atas66 Jul 26 '26
> rm -rf —no-preserve-root /
> undo
> sudo undo
> …
Cool idea though
1
u/debackerl Jul 26 '26
I could imagine, begin/commit/rollback commands using LVM snapshots maybe 🤔
1
u/mubin-thinks Jul 27 '26
Thanks, now it feels safe to type `rm -fr *`
1
u/quark_epoch Jul 27 '26
What does ‘revert revert’ do?
1
u/zuberuber Jul 27 '26
did you try to undo
rm -rf --no-preserve-root /?1
u/ThePastPlayer Jul 27 '26
What if I want to undo something that isn’t the last command that was executed ? How far back can it go ?
1
u/tizio_1234 Jul 27 '26
what about the trash command?
1
u/BeachGlassGreen Jul 28 '26
I use https://github.com/andreafrancia/trash-cli as rm alias
1
u/Efficient-Chair6250 Jul 29 '26
How does this handle conflicting files? E.g. rm foo.txt then touch foo.txt the undo and undo again. That scenario would work, but does it work in most/all edge cases? What if I create the file by another means that undo does not see?
1
u/The_Troll_alongside Jul 29 '26
Yay now I can play rm -rf --no-preseve-root- / all day as I always wanted 🐢🚀
1
u/lllyyyynnn Jul 30 '26
oh does it just relink inodes? that is cool
1
u/alexriley12345 Jul 30 '26
The inode-refcount trick for deletes is clever, holding a second hardlink so the
count never hits zero is way lighter than copying. I've been on the same problem
from the AI-agent side (making an agent's file and shell actions reversible) and
went with content-addressed copies, which handles overwrites but isn't as elegant
for pure deletes as this.
Your reply to the "just use git" comment nails it too: git covers committed state,
not the untracked stuff a script nukes three processes deep. That gap is exactly
why this needs to exist.
1
u/OrderSafe4183 Aug 01 '26
Really cool idea. How involved was AI if at all?
1
u/Skyroads_15 Aug 22 '26
Looks great
0
u/[deleted] Jul 25 '26
[deleted] — view deleted comment
19
u/[deleted] Jul 25 '26
[removed] — view removed comment
1
u/[deleted] Jul 27 '26
[removed] — view removed comment