Live data from Hacker News

How to delete all your files

reddit.com

61–66 of 66 posts

Re: How to delete all your files

#61

Unix Haters Handbook is still surprisingly up to date. http://web.mit.edu/~simsong/www/ugh.pdf page 28 (68) >Some Unix victims turn this filename-as-switch bug into a “feature” by keeping a file named “-i” in their directories. Type “rm *” and the shell will expand this to “rm -i filenamelist” which will, presumably, ask for confirmation before deleting each file.

Oh God that's like something I'd find on Cthulhu's computer

Re: How to delete all your files

#62
post #3

I once saw a friend nearly delete all their files using tip#3 from the thread: > never use only * as a wildcard. A ./* would save you in most cases My friend typod that for /* in an rm -rf command but caught it just in time. They seemed like unnecessary characters to me if it does the same as *, and I don't think they do it anymore, but now I'm not sure which is worse... I suppose good backups just go a long way what…

I just did that last weekend! After an allnighter, which isn't easy for me anymore, I typed: ``rm -rf. /*`` with the dot and the space reversed. When the shell threw an error in my face, I thought, "oh, an extra dot." so I deleted the dot and re-run the command. And there goes my configs and most of the dotfiles in my home dir. Luckily, I have backup for some of those, so it wasn't a complete disaster. I don't trust…

This is why I never use rm when I'm tired or working on important system anymore. I'll just mv the files somewhere for review later. Worst case is I just moved a wrong file and can simply restore it back.

Re: How to delete all your files

#63
post #8

I think Unix Wildcards Gone Wild (2014) [0] demonstrates and explains this rather well (posted 6 and 4 years ago[1][2] - while HN supports reposting, it's probably been posted enough) [0]: https://www.defensecode.com/public/DefenseCode_Unix_WildCard... [1]: https://news.ycombinator.com/item?id=8189968 [2]: https://news.ycombinator.com/item?id=17376895

Also posted 3 days ago [0].

[0] https://news.ycombinator.com/item?id=24220503

Re: How to delete all your files

#64
post #16

It's a shame that 'glob is a generator' did not become the standard way of doing things. It would save so much headache (and make writing programs easier) if command * (or similar syntax) expanded to something like command /some/fd where calls to read(/some/fd) produced "expansion_one␀expansion_two␀expansion_three␀...␀" Though exactly how one would plumb this is its own question.

This is possible if you use "xargs" (which runs a command multiple times with different subsets of the arguments), although it is most useful if commands are aware of null-separation (e.g. old-style "find ... -print0 | xargs -0", before "find" added the "+" option).

Yes, 'find -print0' / 'xargs -0' is the workaround that guided my thinking. (Which was essentially "how can I make 'find -print0 |' easy enough to use all the time, and flexible enough for more than one glob at a time?")

Re: How to delete all your files

#65
post #58
post #46

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.

hah, 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…

Blender 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.

Re: How to delete all your files

#66
post #58

Earlier quoted context omitted.

hah, 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…

Blender 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.

it 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.

Post reply on HN