4 ms·
Once I wanted to do `rm -fr *~` to delete backup files, but the `~` key didn't register... Now I have learnt to instinctively stop before doing anything destru
by _nalply 3y ago
Once I wanted to do `rm -fr *~` to delete backup files, but the `~` key didn't register...
Now I have learnt to instinctively stop before doing anything destructive and double-check and double-check again! This also applies to SQL `DELETE` and `UPDATE`!
I know that `-r` was not neccessary but hey that was a biiiig mistake of mine!
- lostmsu 3y agoI click in Explorer. Have to confirm too. Never been confused.
- laurensr 3y agoYou remind me of that time I wanted to `rm -rf ./*` but the dot hadn't registered... I now avoid that statement.
- _shantaram 3y agoOne time I was debugging the path resolver in a static site generator I was writing. I generated a site ~/foo, thinking it would do /home/shantaram/foo, but instead it made a dir '~' in the current directory. I did `rm -rf ~` without thinking. Command took super long, wondered what was going on, ctrl-c'd in horror... that was fun.
- xp84 3y agoI’m really curious: without cheating by using the GUI, what would be the proper way to delete such an obnoxiously-named directory? Would “$PWD/~” work?
- r3jjs 3y agoA few ways. rm ./~ is likely the easiest. Another option, shell dependent, would be to turn off shell globbing. The `GNU` version of `find` has a `-maxdepth` option so find . -iname '~' -maxdepth 1 -exec rm {} \; would work, but I don't like relying on `GNU` extensions.
- hddqsb 3y agoOr just: rm "~"
- ht85 3y agoIf you ever type really dangerous commands, it is good practice to prefix them with a space (or whatever your favorite shell convention is) to make sure they not saved in your history. One of my "oopsies" involved aggressive <up> and <enter> usage and a previous `rm -rf *` running in /home...
- CoastalCoder 3y agoI didn't know about the space thing! Though for me, I think the greater risk would be from not having a record of what I'd run.
- tetha 3y agoFor entirely critical systems, I by now rather generate a reviewable script and run that. Something along the lines of: find /backups/ -mtime '-30' -printf 'rm -f %p\n' > very_scary_deletes.sh This gives you a static script with a bunch of rm's. You can read that, check it, give it to people to validate and when you eventually run it, it deletes exactly those files.
- _nalply 3y agoThat's clever, only do really dangerous things if you have a way to carefully review the steps. Another way is sometimes: `echo *.txt~` and when you like the result, replace `echo` with `rm`.
- kevincox 3y agoI do this too. Although I usually do `echo rm .txt~` then just remove the `echo` once everything works. Also works well for things like `parallel` and `xargs` where you can do `parallel echo rm -- .txt` and it basically prints out a script. Then you can remove the `echo` to run it.