Mar 21, 2012

Delete files to trash from terminal

In linux rm command cannot be used to delete files to Trash. rm will remove files which cannot be recovered easily. So I wrote a shell script to remove files to Trash. Create a file 'delete' and add the following script to it.

#!/bin/bash

if [ $# == 0 ]; then
        echo "no input files"
        exit;
fi

for item in "$@"
do
  mv $item ~/.local/share/Trash/files
done
Save the file and give executable permission to it chmod ugo+x delete . Then copy it into a folder which is there in the system path. I copied to /usr/local/bin (mv delete /usr/local/bin) It will work with multiple files also.

Try touch file1 file2 file3 and delete file1 file2 file3 . You can see the files in the Users' trash. If the user is root it will go to System trash.

User Trash : ~/.local/share/Trash/files
System Trash : /root/.local/share/Trash/files

For Web Developer

  open -a "Google Chrome" --args --disable-web-security