How to restore deleted items in Linux

I do not want go on and on how some users or even admins can get clumsy and delete files or folders when do not pay attention while using the dangerous command rm -rf on the Linux box. I went trough restore of files on Linux box in last 5 months few times. Bad news – you have to work and spend time to restore what clumsy user deleted, Good news – at least you know that your backup strategy works and you are able to restore when the disaster hits you.

To prevent this happening and be more flexible and be able to restore the deleted files on Linux faster I have found this very cool small utility – trash-cli. It works like charm and if users delete file — hey, can be found in his trashcan. All you have to do to make this is install the utility and add alias in your ~/.bashrc and the rest is taken care of 🙂

So on my Ubuntu box

sudo apt-get install python-setuptools
sudo easy_install trash-cli

Use these commands to get the latest version instead of getting old version with apt-get from repository. Once you have installed the utility use your choice editor and add alias for rm into your ~/.bashrc file

gedit ~/.bashrc
-- once opened just add alias
alias rm='trash-put'
-- save the file and reload your ~/.bashrc
source ~/.bashrc
trash-cli

Now you can try create a file or folder – example test and use rm -rf test. It will be deleted and you should find it in your trashcan. For more info trash-cli offers these commands:

* trash-put     => trashes files and directories.
* trash-empty   => empty the trashcan(s).
* trash-list    => list trashed file.
* restore-trash => restore a trashed file.

Note:

For each file the name, original path, deletion date, and permissions are recorded. The trash command allow trash multiple files with the same name. trash-cli uses the same trashcan of KDE, GNOME and XFCE.

Download link is here . It is also available for Red Hat and Fedora as rpm package and you can get them here

[easyazon-image align=”none” asin=”0596154488″ locale=”us” height=”160″ src=”http://ecx.images-amazon.com/images/I/316lMugY-IL._SL160_.jpg” width=”108″]

Quick Update: Tried to install on Red Hat ES5 – no go, issue with python dependencies, I will need to play with it before I can tell for sure this will work on Red Hat or CentOS 🙁

Leave a Reply