About nixCraft

Linux recover deleted files with lsof command - howto

Posted by Vivek Gite [Last updated: November 17, 2006]

Almost 2 years back I wrote about recovering deleted text file with grep command under UNIX or Linux.

Michael Stutz shows us how to recover deleted files using lsof command.

From the article:
There you are, happily playing around with an audio file you've spent all afternoon tweaking, and you're thinking, "Wow, doesn't it sound great? Lemme just move it over here." At that point your subconscious chimes in, "Um, you meant mv, not rm, right?" Oops. I feel your pain -- this happens to everyone. But there's a straightforward method to recover your lost file, and since it works on every standard Linux system, everyone ought to know how to do it.

Briefly, a file as it appears somewhere on a Linux filesystem is actually just a link to an inode, which contains all of the file's properties, such as permissions and ownership, as well as the addresses of the data blocks where the file's content is stored on disk. When you rm a file, you're removing the link that points to its inode, but not the inode itself; other processes (such as your audio player) might still have it open. It's only after they're through and all links are removed that an inode and the data blocks it pointed to are made available for writing.

This delay is your key to a quick and happy recovery: if a process still has the file open, the data's there somewhere, even though according to the directory listing the file already appears to be gone.

Read more at Linux.com

However recovering files under Linux is still hard work for new admins. I highly recommend backing up files regularly and storing backup offsite.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. sridhar Says:

    i think the OS files in my solaris server have been deleted accidentally.i would like to know if there is any way to recover the files.

  2. Shakeel Says:

    I delete a whole data in home folder by rm -rf * then
    how i recover the data pls reply me

  3. mondarino Says:

    Is is not correct, This is for open-deleted files

  4. Madan Says:

    I delete a whole folder which having data by rm -rf * then
    how i recover the data pls reply me

    thx in adv - madan

  5. abhi Says:

    I accidently deleted a whole folder from my home directory.
    How i recover my lost data plz reply

  6. danny0085 Says:

    Here I give you a link with a useful tip


    http://tips-debian.blogspot.com/2008/04/recover-erased-data-ext2ext3.html

  7. guna Says:

    I want recover the deleted files and directory command. Please help me give proceture.

  8. manoj Says:

    Hi Guys,
    Accidentaly I deleted all of my folders using
    rm -rf *
    It contained some important data. I need those
    data back.Can any body help me in this regard.

    Thanks in advance,
    Manoj.

  9. manoj Says:

    This is a nice site which can help us in urgent.

  10. Ashish Amre Says:

    Some one destroyed all my vpses now I want to recover data please help me how to recover that data.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.