I believe that every linux user at one point in time must learn this painful lesson firsthand before actually learning the importance of backups, as well as paying attention to detail and being careful.
For instance, if you're deleting wierd looking files, you could first run commands on that wierd file that have no side effects and that don't make changes to your data. For instance, had you run
cd ~
before trying to delete the folder, you would have seen that it would instead change directory to your home folder, not the ~
folder. Once you go through enough troubleshooting steps to learn the true command you would need to correctly cd
into the ~
folder, then you could press your up arrow key to pull the last command from history and then change cd
to rm
and then and only then try to delete the folder.
I suggest taking steps like this before performing any action that is permanent. It's not permanent or foolproof, but you have a much better chance of preventing those oops moments if you take this degree of care when performing actions that have side effects.
I'm just curious: who created the folder named '~' which you found on your computer? – unforgettableidSupportsMonica – 2015-10-07T16:51:58.600
Where do I get my '"sudo rm -rf ~"-without-a-backup'-badge? I want to claim it right now. – Daniel F – 2016-01-14T15:30:18.540
Don't name folders "~"? ;-) – Craig – 2016-12-11T07:18:48.343
18What file system? – Tarnay Kálmán – 2011-05-05T18:39:03.353
1If you just want to restore your ability to login, login as root,
mkdir /home/{your username}
, and thenchown {your username}:{your group} /home/{your username}
. – LawrenceC – 2011-05-05T18:56:26.6576Clearly you people have no sense of humor. – Blomkvist – 2011-05-05T19:08:09.297
If you get in the habit of using
shred
instead ofrm
, you should end up ok in the end. – Thomas Eding – 2011-05-06T03:42:32.67321Though this doesn't directly answer your question,
rm -rf "~"
with quotes will look for that literal name instead of expanding it. But I would be scared to use that anyway – I would use something likels
orcd
first to verify I get the right dir, or delete the folder from a GUI file manager. Perhaps first rename the dir (mv "~" tilde
), verify and then remove. – Henrik N – 2011-05-06T05:58:56.7372
For the future, don't use rm interactively at the command line. Use a utility like trash and you 1) can't make the same mistake again and 2) can't get used to a poor shell alias of rm that will cause you trouble.
– Fred Nurk – 2011-05-06T07:06:44.357@Fred
rm -ir ~
will printexamine files in directory /Users/danielbeck
. It's safe enough for use like this. – Daniel Beck – 2011-05-06T07:18:49.9431@DanielBeck: If you have the discipline to always type the option, that works fine. In my experience, users are more likely to drop the option and go back to using rm directly. – Fred Nurk – 2011-05-06T07:22:34.743
9@HenrikN: ./~ instead of "~" does the same, but also works with other common problematic filenames, like those that start with dashes and look like options. – Fred Nurk – 2011-05-06T10:57:17.907
@FredNurk Just not using
-f
is already an improvement. – Arda Xi – 2011-05-06T13:07:34.0171
Blomkvist As I reported and commented on your answer, I assume your comment was directed at me. Just post your non-answers (i.e. comments) as actual comments next time and nobody will care. They'll probably even help you get the Pundit badge. I liked the story and would have upvoted a comment.
– Daniel Beck – 2011-05-06T17:15:14.9701Like @Henrik N's comment this is not a solution either. But I always use
gvfs-trash
(Ubuntu) even if I'm at the command line, instead ofrm
. It can delete directories or files, and unlikerm
there is a recovery option. I made analias del=gvfs-trash
in my.bash_aliases
and alsoalias
edmv
tomv -i
to avoid the other kind of irreparable error. – isomorphismes – 2012-09-01T02:33:46.140Just be happy it wasn't
rm -rf /
orrm -rf .
... ;) – sjas – 2013-02-24T17:48:02.173