How to move files to the trash from the command line

I’m not fan of the command line. But it’s necessary if you want to get things done. Any linux / mac command line user should know how to use the rm command. But what if you want the files to go to the trash can instead? Here’s how to do that on mac.

First, get yourself brew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then all you have to do is this:

brew install trash

From then on, all you have to do is type:

trash my-file.txt

Your file will then be moved into the trash can. What if you want to use rm to do that? Just don’t think that way. There’s a way to do it, but what happens when you’re so comfortable using rm to move things to the trash, and you’re on a system that doesn’t have rm setup to move files to the trash can? You’re gonna hate life, and I don’t want that to happen to you.

I’m a fan of Ubuntu, so here’s how to move files to the trash can on Ubuntu:

apt-get install trash-cli
touch test.txt
trash-put test.txt

View files in trash:

trash-list

Finally, here’s how to empty the trash:

trash-empty

There you go.

Conclusion

You’ve learned how to move files to the trash can on Mac & Ubuntu (Linux). Now you get a second chance with the files you delete. Remember, with great power, comes great responsibility. Use with care.

Leave a comment

Find the Best SEO in Fort Lauderdale, Florida (Plantation SEO) | Drupal & Worpress Develpment