Add ‘trash’ functionality to Ubuntu Server
If, while working on the console of the Ubuntu Server, you often have to delete some files, you might be prone to accidentally delete something you actually needed to keep. The problem with Ubuntu Server is that its ‘rm’ command deletes immediately. Fortunately, there is ‘trash-cli’ package that can help.You can install it by using apt-get commend:
apt-get install trash-cli
After installation, you will have several new commands available.:
- trash-empty – to empty the trash
- trash-put (or short: trash) – to move the file into trash
- trash-list – to list the trash contents
Now, you only have to stop using the rm command. You can make it easier by creating a new alias
- in the ~/.bash_aliases file for current user
- in the /etc/skel/.bashrc file for all users
Set alias as follows:
alias rm='/usr/bin/trash'
You can notice that /etc/skel/.bashrc checks each users home directory for the .bash_aliases file and executes it.
if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi
The new alias will be available only on new terminals. In order to get them on existing terminals, type the following:
source ~/.bashrc source /etc/skel/.bashrc
You can check if the new alias is active by typing:
command -v rm alias rm='/usr/bin/trash'
The trash command has the same options and switches as the rm command, so you shouldn’t have to modify any scripts you might be using.
Note: Do remember to empty the trash every once in a while.