Live data from Hacker News

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

news.ycombinator.com

31–40 of 76 posts

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

#33
My “alternative” to rm is to use mv directly. I just mv files aside whenever I am not 100% confident they are safe/ready to delete permanently.

Personally I’m not a fan of shell environment customizations like this because they are often fragile and may vary between systems. I like to know exactly what commands I’m executing.

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

#34
post #26

Earlier quoted context omitted.

Now let's delete them after roughtly 30 days: alias del="mv -t ~/.Trash/ ; find ~/.Trash/ -mtime +30 -exec rm {} \;"

This is not fine, as deleting a small file can be very long if there's a large file to be deleted in the trash.

Yeah running the delete in the user's crontab (i.e. in the background and on a schedule) would be a better option IMO.

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

#35
post #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.

There's plenty of good reasons not to use shellscript, but someone not knowing the difference between "$@" and $* isn't one of them. This is prominently documented in Bash's documentation: https://www.gnu.org/software/bash/manual/html_node/Special-P...

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

#36
post #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.

What? No, come on. You can’t extrapolate “someone didn’t read the manual” to “don’t use shell scripting”.

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

#37

Earlier quoted context omitted.

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 {} \;"

This fails on directories, as the -r switch was not included:

    mkdir foo; del foo
and including it will spawn file not found errors for the contents of the foo directory, if any.

EDIT: See also neighbor comment about appending filenames!

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

#38

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

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

This fails on non-GNU mv(1) binaries such as macOS.

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

#39
post #3

For Linux users: also look into the trash-cli [1] package, which complies with the FreeDesktop.org trash specification and remembers the original path, etc. so that trash items can be restored even with filename collisions. Then it's trash-put my_file.txt [1] https://github.com/andreafrancia/trash-cli

Until at least an year ago, the Ubuntu version (and likely, the upstream on), wouldn't work on certain filesystems.

I'm not sure about the current state, but one needs to test is very carefully before using it.

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

#40
post #3

For Linux users: also look into the trash-cli [1] package, which complies with the FreeDesktop.org trash specification and remembers the original path, etc. so that trash items can be restored even with filename collisions. Then it's trash-put my_file.txt [1] https://github.com/andreafrancia/trash-cli

Until at least an year ago, the Ubuntu version (and likely, the upstream on), wouldn't work on certain filesystems. I'm not sure about the current state, but one needs to test is very carefully before using it.

Which filesystem were you using when you encountered trouble with it? What happened when you tried to use it? Did it warn you about the filesystem issue? Did it delete rather than trash?
Post reply on HN