Replacing rmtrash on Mac and replacing rm on Linux

rmtrash can no longer be installed with Homebrew

It seems that it was recently removed from Homebrew because the license is opaque and there is no response from the author.

It seems that registration of another rmtrash is being considered, but it cannot be used now (December 14, 2020), so we will consider an alternative.

Alternative candidate

On a Mac, I want something that can be thrown from the command line into the system trash.

  1. trash in Homebrew
  2. [macOS] I wrote a script to delete from the command line to the Trash
  3. I made gomi, a trash can tool for rm in Go language

The trash in 1 is almost the same as the rmtrash. It's easy to install with Homebrew. But I couldn't get the deleted files back from the trash that I opened in the Finder. (I forgot if rmtrash could be returned from the trash.)

2 needs to download the script, but you can restore the deleted file from the trash can opened in Finder.

3 is highly functional, but recent versions seem to have lost the ability to throw it in the system trash.

For the time being, the script called trash in 2 seems to be good, so I will use it for a while.

trash settings You can download or copy the script from here and put it with execute permission where the path passes.

I aliased it to rm. I also added the -r option so that the directory can be deleted.

if type trash > /dev/null 2>&1; then
    alias rm='trash -r'

Replace rm with Linux

In Linux on a server such as a supercomputer, I create a directory (~/.Trash) that becomes a trash can by myself, and move files to it once with mv without using rm.

You can create a directory anywhere you like, so on servers that often use / work, create it under/work.

Alias ​​setting.

if [ -d ${HOME}/.Trash ]
    alias rm='mv --backup=numbered --target-directory=${HOME}/.Trash'

If the --backup = numbered option is specified, if the same file name exists in the move destination, the file name will be numbered and moved instead of overwriting.

You can move files to a directory specified in advance with the --target-directory option.

Create a script that empty the contents of the trash can directory that you created, and give execute permission to the location where the path passes.


rm -rf ~/.Trash/*


Recommended Posts

Replacing rmtrash on Mac and replacing rm on Linux
Recording and playback on Linux
Catalina on Mac and pyenv
MQTT on Raspberry Pi and Mac
I installed Linux on my Mac
[UE4] Build DedicatedServer on Windows and Linux
Install wsl2 and master linux on windows
I want to use Linux on mac
Install and launch k3s on Manjaro Linux
Notes on building Python and pyenv on Mac
Learn sshd_config and authorized_keys (on Amazon Linux 2)
python on mac
Let's integrate Django and apache (httpd) on Mac! !!
How to switch between Linux and Mac shells
Invert screen output vertically and horizontally on linux
Zsh and prezto installation work log on Mac
Remove old pyenv environment on Mac and update
Try importing MLB data on Mac and Python
Install procs, an alternative tool for ps, on Linux (also available on Mac and Windows)
Install Python3 on Mac and build environment [Definitive Edition]
Specify the volume on linux and make a sound
Maintain directory structure on Linux and move old files
Install selenium on Mac and try it with python
Installing Python 3 on Mac and checking basic operation Part 1
MySQL installation on Aws Linux 2 and test data preparation
Compile and install MySQL-python for python2.7 on amazon linux
Install Docker on Arch Linux and run it remotely
Daemonizing processes on Linux
Install pyenv on mac
OS and Linux distribution
jblas on Arch Linux
Linux (WSL) on Windows
NAT router on Linux
Pyenv + virtualenv on Mac
Install Ansible on Mac
Install Python on Mac
Install Python 3 on Mac
numba installation on mac
Develop .NET on Linux
Wake on lan on Linux
Monitor traffic on Linux
Linux: files and directories
Update vscode on linux
Try NeosVR on Linux
Install Python 3.4 on Mac
Install mecab on mac
Check capacity on Linux
Install mecab-python on Mac
Try deepdream on Mac
LiveUSB creation on Linux
Linux operation on Win10
Notes on building TinyEMU and booting the Linux kernel on Emscripten
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Building a Python environment on a Mac and using Jupyter lab
Test Python with Miniconda on OS X and Linux with travis-ci
I installed FreeCAD on Linux (Ubuntu) and created an icon
Intuitive password management with aws ssm on Mac / Linux alias
Find the most F-word commit on Linux (git and later)
Deep Learning with Shogi AI on Mac and Google Colab
How to copy and paste command line content without mouse in bash on Linux or mac