Wednesday, December 23, 2009

Trash can or Recycle bin in Linux Desktop (managed from console)

 

Linux Desktops, at least Gnome and KDE has a trash can, where your deleted files go, (only when deleted from a Desktop utility).

Now if you want to manage it from the console, you can, first we need to know that the trash can is only another folder in the File system structure and it is located at:

$HOME/.Trash

So you can send files to Trash just moving them to there, as an example, lets suppose you have a file in your home called example.txt and want to move it to the trash can.

mv $HOME/example.txt $HOME/.Trash/

Whenever you may want to recover it, just move it to its original location or to any other you prefer, just like this:

mv $HOME/.Trash/example.txt $HOME/

and you are done, if you want to purge your trash can, just enter.

rm -rf $HOME/.Trash/*

BE AWARE: This action can not be undone!!, so use with care

you can even create a script to use instead of rm in your console, the easiest one is this:

#!/bin/sh

mv $1 ~/.Trash

If somebody can think into a better one, please share with us, hope you may find this info useful.

 
Things You Should Know About Linux !!!