Question:
How can I make the rm
command delete files to the trash by default?
Answer:
If you use the desktop trash, you can delete a file in it with the gvfs-trash
command. Present in almost all desktops.
Install:
apt install gvfs-bin
Delete:
gvfs-trash ./имяфайла
When deleted, a .Trash
folder is created on the current partition according to the specification .
The trash
command is more powerful than gvfs-trash
.
Install:
apt install trash-cli
Delete a file with a simple trash
command. Other commands trash-empty
, trash-list
, trash-put
, trash-rm
(remove file from trash).
trash --help
Usage: trash [OPTION]... FILE...
Put files in trash
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-d, --directory ignored (for GNU rm compatibility)
-f, --force ignored (for GNU rm compatibility)
-i, --interactive ignored (for GNU rm compatibility)
-r, -R, --recursive ignored (for GNU rm compatibility)
-v, --verbose explain what is being done
To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
trash -- -foo
trash ./-foo
The trash
utility can be added as an alias to rm
.
alias rm=trash
rm -v Загрузки/Calendar\ \(1\).ics
trash: Volume of file: /
trash: Trash-dir: /home/eri/.local/share/Trash from volume: /
trash: 'Загрузки/Calendar (1).ics' trashed in ~/.local/share/Trash
Usage example (delete, view list, restore):
$ trash Загрузки/Calendar.ics
$ trash-list
2017-10-24 14:44:49 /home/eri/Загрузки/Calendar.ics
$ trash-restore
0 2017-10-24 14:44:49 /home/eri/Загрузки/Calendar.ics
What file to restore [0..0]: 0
Both utilities are desktop compatible and deleted files will be displayed in the Recycle Bin.