4 ms·
I had a close call one time while trying to delete a directory `~/foo` and its contents. Here's what I typed — can you spot the error? rm -rf ~ /foo I re
by rectang 6y ago
I had a close call one time while trying to delete a directory `~/foo` and its contents. Here's what I typed — can you spot the error?
rm -rf ~ /foo
I realized after a second or so and hit CONTROL-C. Nothing seemed to have been deleted, so I think it may have been still winding up.
- garaetjjte 6y agorm is not like explorer.exe and is rather fast with destruction, so I guess you must have deleted some dotfiles.
- rectang 6y agoCould be. This was on a Mac, around 2013, so it should have been pretty snappy. Whatever it got I never noticed. Maybe it was trawling through a bunch of build detritus in `~/.cpan` or something.
- andrewmackrodt 6y agoI accidentally did the same on my Mac via a shell script where I assumed mktemp worked the same as gnu mktemp, it does not. IIRC it was my /Applications directory that was first to be hit; most of the directory was unaffected due to file permissions but it did delete some files despite me catching thee error and sending sigkill within seconds.
- gcpwnd 6y agorm -rf on root will query for confirmation. Not sure if this happens on all systems or even all top level directories.
- em-bee 6y agohah, i had a tool where i configured ~/something as a target directory in its config. except that the tool did not understand ~ and literally created a directory named '~' guess what i typed to remove it? i lost a lot of work that day. since then i developed the habit to always only use rmdir for directories, and first go into the directory to remove files with rm. i also avoid rm * by finding some common parts like an extension that most files share. i don't want rm * to be in my history where i might accidentally call it.
- likeclockwork 6y agoBlender tried this on me a few months ago. I used mv to rename the directory before deleting it though, the fear caught me as soon as I realized I had a directory named ~ sitting in my home directory.
- em-bee 6y agoit tried to blend in ;-) mv is a clever idea. rename to something safe, which can be undone if you get it wrong. i use a similar approach when deleting a lot but not all files from a directory. i first move the files into a new directory, double check that every file is in the right place and then delete the new directory safely.