Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
Another handy trick I use to avoid mistakes with rm or mv (remove or move) commands is to simply use ls (list) with my wildcard until I'm 100% certain I've got it listing only the files I intend to delete or move, then I just up-arrow to my ls command and edit that line to mv or rm instead of ls.
Most all linux systems will allow you to open a terminal in a directory then type in the command: sudo rm (followed by a space) then simply drag and drop the file you want to delete onto the terminal and press enter/return.
An easy way to get accustomed to file & directory management in linux (as any other OS) is simply make dummy directories and files and delete, copy and move them around when you get some spare time. It'll be okay.
So, about the original question of a true "Undo" option, one way you can really truly undo actions in any operating system is to run that operating system inside a virtual machine like VMWare or VirtualBox and just take a VM "snapshot" every time things are all feelin' "perfect", and just before you do anything you think is gonna be "risky". Then you've always got snapshot points to fall back to no matter how badly you screw stuff up inside the VM. Great way to practice things that scare you, or test things you know are gonna trash things… Virtual machines are a great way to explore and take risks with computer stuff without any actual risk involved.
Dry-run is an option some programs have. Apt on Debian/Ubuntu for example. It tells you what it would install/remove without actually doing it. The closest to a dry run derivate for rm would probably be "ls". If you're often unsure what a program like wget or youtube-dl will download, do it in an empty temp dir.
[DO NOT RUN THIS]
ok, keep calm, just don't reboot yet...
this of course makes sense for only SOME operations, while for others the damage may not be straightforward to revert
it's an interesting concept (but of course totally fictional for now), that would probably sit well in a Stack Exchange question...
... hum, probably has been asked there already...
yep, there is a few takes on the same idea and a zillion questions on undoing specific things if anyone is interested:
https://stackexchange.com/search?q=undo+linux+terminal+commands
Don't run stuff you don't know what it's going to do.
second. Use timeshift to keep backups
Or if you are really fancy. Opensuse uses btrfs by default and creates read-only snapshots are every interaction with YaST or Zypper. It makes it almost impossible to permanently brick your system due to how easy a recovery is. Although that features was likely just made for enterprise users and is just there in tumbleweed, because why not?
That way you could have an "undo" command
Other folks already covered this better'n I could it would appear, including making mention of "snapshot" capable filesystems like BTRFS and snapshot style backup tools like TimeShift, so I'ma defer to those answers.
Piping output to /dev/null does nothing to protect against potentially harmful commands, and is actually not fun if used in combination with potentially damaging commands, because it's a convenient way to throw away unwanted output so that you never see it at all. This of course is bad when you want to see output (like from a damaging command) to help you recover from a bad situation. Only ever pipe your output to /dev/null when you really want to totally throw away / hide that output because you know it's pointless debug details or other unneeded information you're throwing away on purpose. Anything piped to /dev/null goes into a "black hole" never to return.
Note: Piping to /dev/null throws away output but not actions. The actions are still performed, just with no visible output from the commands being run.
meanwhile a dry-run would be something like:
Hey, I gotta solution for that one too… Nothing really wrong with the rm command other than the danger of misusing it accidentally, or with a bad wildcard, but if you're so seriously concerned about that danger as you appear to be, there's a couple of ways you can improve your safety surrounding copying, moving, and removing files with commands.
My first suggestion (since you mentioned file managers and their "trash" or "recycle bin" safety net) is that you can search and install "trash-cli" in your package manager. This gives you a "trash" command which interacts with the system standard trash/recycle bin facilities to move deleted files there, instead of removing them entirely like rm does.
Second suggestion is to check into cp, mv, and rm and their "interactive" flags, and your favorite shell's means of defining command aliases. I have cp, mv, and rm all aliased to default to using the -i (interactive) flag, where I get asked yes/no are you sure for any dangerous actions which might overwrite or remove data.
Regarding that original request; Perhaps someone crafty could cobble together a tool using a combination of "trash-cli" and a backup/snapshotting tool or filesystem that fairly closely fits what you describe, but as yet I personally know of no such existing tool. That's not to say no such thing exists at all, as I still don't know every tool available to we Linux users as there's simply far too many really slick tools out there, and folks writing new ones daily.