Move to Trash CLI on macOS

Fri, 30 Apr 2021 09:44:15 GMT

Problem

On Linux, you can move files/folder to Trash from CLI using command called rm. On macOS, there is also a command called rm, but this command will delete your files/folder permanently instead of move them to Trash. By default, you must do it via GUI.

Solution

Install the Homebrew package trash using command:

brew install --HEAD macmade/tap/trash


brew install --HEAD macmade/tap/trash

You can alias the default rm command to trash, using the following line into your shell profile file:

if [ -f /usr/local/bin/trash ]; then alias rm="/usr/local/bin/trash"; fi


if [ -f /usr/local/bin/trash ]; then alias rm="/usr/local/bin/trash"; fi

Then restart the terminal application.

Now, the command rm will move your files/folder to Trash instead of delete them permanently.