Live data from Hacker News

Stop Using `rm` in Bash. Use `del`

news.ycombinator.com

11–20 of 76 posts

Re: Stop Using `rm` in Bash. Use `del`

#11

rm is for removing stuff. If you don’t want to remove the file, use mv. Take care when entering commands, if it’s important that you don’t mess up, spend an extra second. Don’t run around shooting rm -rf as super user. With great powers comes great responsibility.

Would be nice if filesystems were garbage collected, though. I don't see a fundamental reason why rm couldn't be undoable the second after you issue it.

It usually is: http://extundelete.sourceforge.net

Re: Stop Using `rm` in Bash. Use `del`

#12
post #2

I wish something like this were built into kernel filesystem driver. All deletions automatically go to this specific place in the filesystem.

This would be fun as an experiment to see how quickly it fills up the drive, but probably utterly useless in production. A lot of stuff is creating and deleting files all the time, e.g. logrotate.

Re: Stop Using `rm` in Bash. Use `del`

#14

While not an alternative, please bugfix your bash: mv "$@" ~/.Trash/ https://github.com/koalaman/shellcheck/wiki/SC2086

Even simpler: alias del="mv -t ~/.Trash/"

Now let's delete them after roughtly 30 days:

  alias del="mv -t ~/.Trash/ ; find ~/.Trash/ -mtime +30 -exec rm {} \;"

Re: Stop Using `rm` in Bash. Use `del`

#15
post #2

I wish something like this were built into kernel filesystem driver. All deletions automatically go to this specific place in the filesystem.

...and then how do you delete it from that specific place when you are sure you want it gone? A new syscall?

In seriousness tho, if you're ever wondering why such and such thing is not builtin into the kernel read up on separation of policy and mechanism eg:

https://en.m.wikipedia.org/wiki/Separation_of_mechanism_and_...

Re: Stop Using `rm` in Bash. Use `del`

#16
This is another example that shows that Bash (and similar shells) should not be used for scripting.

It's great for the command line, but for scripting there are much better, cleaner, faster and safer alternatives.

Re: Stop Using `rm` in Bash. Use `del`

#17

I've never liked the idea of a trashcan, and usually shift-delete when I'm in the gui. Deleting shouldn't be done casually, but a ui shouldn't second guess a user any more than it has to.

I habitually shift+delete too, but I won't say I've never made a mistake.

It's much less hazardous doing this when everything is in source control, though. :)

Re: Stop Using `rm` in Bash. Use `del`

#20
This was one of the first things I realized I had to do back when I installed a Red Hat 3.0 for the first time.

My alias was for rm itself. I replaced it completely, as the habit of using rm is hard to forget. Today I don’t use an alias anymore.

Post reply on HN