rm is efficient, but it is also permanent. A typo or an incorrect glob can remove important files without a recovery path, because command-line deletion normally bypasses the trash directory used by graphical file managers.

Alternatively, a safer command-line workflow can keep the familiar rm interface while routing deletions through the trash first.

One implementation uses the following architecture:

  1. Frontend: rmtrash, a drop-in rm replacement.
  2. Backend: trash-cli, which manages the actual trash operations.
  3. Cleanup: a cron job that permanently removes old trash entries.

§1. Frontend: rmtrash

rmtrash is a wrapper around rm. It accepts common GNU rm flags such as -f, -i, and -rf, but sends files to the trash instead of permanently deleting them.

Place the script in a directory on PATH:

1
2
cp rmtrash ~/bin/rmtrash
chmod +x ~/bin/rmtrash

Configure rm as a shell alias for rmtrash:

1
alias rm=~/bin/rmtrash

After reloading the shell, rm foo.txt sends foo.txt to the trash instead of deleting it permanently.

§2. Backend: trash-cli

rmtrash depends on trash-cli for the actual trash operations. Install it with pipx:

1
pipx install trash-cli

This exposes commands such as trash-put, trash-list, trash-restore, trash-empty, and trash-rm in ~/.local/bin/.

The trash itself follows the FreeDesktop.org layout under ~/.local/share/Trash/:

1
2
$ ls ~/.local/share/Trash/
files info
  • files/ - the actual deleted files and directories
  • info/ - .trashinfo metadata files containing the original path and deletion timestamp

For example:

1
2
3
4
5
6
$ ls ~/.local/share/Trash/info/
foo.txt.trashinfo project/ screenshot.png.trashinfo
$ cat ~/.local/share/Trash/info/foo.txt.trashinfo
[Trash Info]
Path=/home/user/docs/notes/foo.txt
DeletionDate=2026-05-09T20:45:00

Useful commands:

1
2
3
4
trash-list                   # see what is in the trash
trash-restore # interactive restore
trash-empty 30 # permanently delete items older than 30 days
trash-rm foo.txt # permanently remove a specific item

§3. Cleanup: cron

The trash still needs periodic cleanup. A daily cron job handles this:

1
@daily ~/.local/bin/trash-empty 30

This permanently deletes trash entries older than 30 days. The result is a safer command-line rm workflow with a bounded trash directory.