Create a file delete command that uses the trash

As mentioned several times in this book, the rm command doesn't have a trash facility. once files are deleted, they're gone forever. However, you can create your own trash command which, when used at the prompt, will move files and/or folders to Ubuntu's standard trash folder. The files can then be recovered, if desired, or permanently deleted in the usual way by emptying the Trash folder.

To add the new command, you'll have to create an alias. Aliases are discussed more in Tip 259, on page 299, but for now it's enough to know that you'll need to edit the .bashrc file in your /home folder and add a line to the bottom, as follows:

1. Open a terminal window and type gedit ~/.bashrc.

2. At the bottom of the file, add the following new line: alias trash="mv -t -/.local/share/Trash/files --backup=t"

Save the file, close Gedit, and open a new terminal window to test your new command. To delete filename.doc, for example, you would type trash filename.doc. The new command will work on folders too, and multiple files/folders can be specified one after the other (for example, trash filename1 .doc filename2.doc).

Was this article helpful?

0 0

Post a comment