Live data from Hacker News

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

news.ycombinator.com

41–50 of 76 posts

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

#42

Time Machine.

For the unaware, Time Machine is the macOS built-in backup system. Once configured, it takes frequent filesystem snapshots and syncs them to a connected storage device. If the file being removed is included by those backups, and existed long enough to be in a snapshot, then you can restore it from the TM backup. Neither of those criteria are guaranteed, as when working with files in a Terminal or bash script you can easily create and remove files with names and/or locations that exempt them.

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

#45

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 does not work. The arguments to `del` get appended at the end, after `find`. You want this:

  del() { mv "$@" ~/.Trash/ && find ~/.Trash -mtime +30 -delete }
I also replaced the unnecessary exec by find's builtin -delete

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

#46
post #18

Or use a snapshotting filesystem, so you can simply go back in time if you mess up.

I use borg backup running via cron multiple passes per day. When needed you can mount any backup as a file system for easy restoration. Yes, short-lived files can't be recovered, but that's something I am willing to live with.

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

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

Nothing about that is especially prominent (its just regular documentation), and then you still need to consider how any given utility will interact with one word vs multiple words.

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

#50
post #13

I move to /tmp and it gets deleted on next reboot.

/tmp is a ramdisk on some systems, which makes this particular approach a very risky endeavor to use as a global replacement for ‘rm’ as the OP suggests.

Sure, also it works for me because it is on a system that is frequently turned off. If it would have to stay on for a long time it would fill /tmp with garbage.
Post reply on HN