linux Oops: I deleted an improtant file, can I undelete?

By: | Comments: 53 Comments

Posted in categories: Computer Tips, Work related

Linux does not offer a file undelete or unerase mechanism, especially in command line.

To undelete a really deleted file, it take guru’s work like in

http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html

This is the last thing one can do.  However, if you take a few precautions, you may save yourself easily.

There is a small package named ptrash, which can be found at http://pjp.dgplug.org/tools/, and has been included in plenty of linux repos.

You can just try

yum install ptrash

to see if it is in your repo.  If not, go to the website for a tar ball.

When installed, you may still forget using the nice new command  “ptrash” for delete.  To avoid this, you need to add a line in your ~/.bashrc as

alias rm=”echo file will be sent to \.trash\, use ptrash -d to purge.; ptrash -iv”

This will first remind you that your file will be moved to

~/.trash

folder, instead of being silently deleted.

In case you did it wrong, you can either move them back or use ptrash’s undelete option.  The echo remind you that ptrash is the magic key.

Then log off and log in again to have a try.  It also work on folders and wildcards.

For purging the ~/.trash folder, you can either setting up a cron job or leave it to yourself.

Enjoy.

53 Comments

Leave a Reply