Earlier quoted context omitted.
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 has nothing to do with the OP, but I always rehearse my deletions with "ls -d", and after seeing the output hit the up arrow in my command history and replace it with the rm command I wanted to attempt. I also never use -r without intention - a lot of people use it habitually even when not deleting a directory. Lastly, I never -f, I just chmod first.
How to delete all your files
51–60 of 66 posts
Re: How to delete all your files
#52I 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.
Re: How to delete all your files
#53I would suggest people use the rsync --dry-run feature when using wildcards or working on something sensitive.
Re: How to delete all your files
#54Another example of why shell languages are insane interfaces. Only someone who works on writing shell scripts all day could keep in their head all the things like this that could go wrong and how to defend against them.
Sadly this is one of the sanest answers. ./* or always using -- are coping mechanisms . We've internalized the UNIX warts so hard that we no longer perceive them. I've moved to writing scripts in python instead. It's horribly verbose, but at least it's predictable and doesn't require the use of noisy disclaimers on every call to defend against rare cases. There's definitely a need for a terser sane scripting language…
I can avoid most of the pitfalls of writing in sh, while still being able to glue external programs together.
For the record, I'm only writing it in Rust because I enjoy it, not because "Rust is the one true way".
Re: How to delete all your files
#55https://www.defensecode.com/public/DefenseCode_Unix_WildCard...
BTW, shellcheck detects this sort of thing:
Re: How to delete all your files
#56An `rm -rf ` always has the potential for some desaster. Especially if you are calling it from bash history via `Ctrl + r` and hit return too fast without editing the argument after `-rf`. Actually the rm command should move files into a `~/.Trash` folder instead of immediately removing them.
At least ctrl-r shows you what command you're about to execute. I often see advice about character sequences in bash that expand to the last command or arguments in the last command, but I have never felt comfortable using them because I can't double-check the command.
Re: How to delete all your files
#57Earlier quoted context omitted.
rm is not like explorer.exe and is rather fast with destruction, so I guess you must have deleted some dotfiles.
Could 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.
Re: How to delete all your files
#58I 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.
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.
Re: How to delete all your files
#59Earlier quoted context omitted.
Yes thanks. I thought running rsync with a "*" looked odd, but didn't completely understand why until now.
Funnily enough, rsync is one of the commands for which you might be more tempted to use * instead of going up a directory, because the relative path names go over the wire.
rsync also used the local/only/path/./local/and/remote/path convention where the path before the /./ is not sent to the remote side
Re: How to delete all your files
#60“Because the share contains a file named exactly "--delete", and since it gets sorted first, rsync thinks it to be an argument and deletes everything.” Also because Unix made the mistake (edit: calling this a mistake may be unfair) of having the shell expand wildcards. If it had provided a library for doing that, the “rsync thinks it to be an argument” part wouldn’t happen. Alternatively, a file system could sort hyp…
This use of / for options goes way back to VMS apparently[0] and changing the path separator to avoid ambiguity does seem sensible. Of course, Windows has its own quirks like CON.