Live data from Hacker News

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

news.ycombinator.com

61–70 of 76 posts

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

#61

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

Correct me if I'm wrong, but wouldn't that instantly delete all moved files which are older than 30 days since mv keeps the mtime?

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

#63

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 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

Thank you, it's painful to see people providing replacements for critical commands like `rm` without understanding basic shell features like aliases.

And just a reminder everybody please don't run random scripts you find on the internet.

P.S. you need a semicolon before the close brace :)

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

#65
post #61

Earlier quoted context omitted.

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

Correct me if I'm wrong, but wouldn't that instantly delete all moved files which are older than 30 days since mv keeps the mtime?

You’re not wrong :)

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

#66
I too have my share of reinventing the trash functionality :)

garbage-io has some features that scratch my own itches:

- Trash files with the same name without clashing - Delete things from trash directory base on deletion time and file size - Hide the deleted files/directories before moving them, in case moving them takes a long time (I later think this was a bit over the top...) - The smart deletion can also be used for e.g. ~/Downloads

I do feel that a better approach would be something that works alongside the trash functionality instead of replacing it, though.

https://gitlab.com/phunehehe/garbage-io

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

#67

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.

This fails in the GUI in cases such as if you accidentally hit navigation keys close to the Del key, like Home, End, etc. In those cases you may accidentally change the file selection in the same movement as the deletion, and then you whack the wrong file.

If you’re the person in charge of making the delete operation the best and safest it can be, you do not have the luxury of yelling at users to just be more careful, because the data shows very plainly that doesn’t work (despite this being the approach most IT people seem to think is acceptable). In this role, with these constraints, the inevitable conclusion is the make a trash can.

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

#68
post #23

Earlier quoted context omitted.

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.

Most have SSD drives now that trims the space on delete. Not sure how easy it is to mark regions on the SSD for "undelete" when it has been trimmed. In some cases the deleted region of the drive may even be mapped to another place on the memory chip itself to cycle it.

On Linux at least, it's not recommend to run continuous TRIM (aka "discard"). Instead, you can run fstrim on a timer to clean things up periodically. Most SSD's can actually do either, but discard is recommend against for NVMe drives, and many SSD's have bugs, so overall periodic trim is the way to go.

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

#69

Earlier quoted context omitted.

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?

I think the problem was with Btrfs subvolumes. There are old bugs filed on Ubuntu, not sure if they're current, e.g. https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1442....
Post reply on HN