Recovering files after rm in Linux

August 17, 2010 at 11:50 pm Leave a comment

This is in brief how I recovered 20+ files I had lost after an accidental ‘rm’. It was simpler than I expected.

My case

  • System: Ubuntu
  • Time I started recovery: 1 hour after having done ‘rm’
  • Files recovered: html, css, .py
  • How to

  • Run `df` to find out which drive the files are in. Eg. /dev/sda1, or /dev/sd6
  • `sudo vim /etc/foremost.conf` You will see various file formats and need to uncomment the ones you want. In my case I needed to add .py files. For .py files you need to specify how the files usually start, so I used the “import” expression as a match. For html files you can use the “” tag or something of the sort.
  • `sudo foremost -i /dev/sda6 -o recovered_files` (-o is for the directory to where you want to output the recovered files). This will start running and go on for a while trying to recover as many deleted files as it can find. In the meanwhile you can do the next step
  • Look inside the recovered_files folder. Here there should be a directory for each file extension you are looking for. In my case I find a py, html, and css folder. Inside each of those folders you will find hopefully numeric file names with the extensions. (Eg. 2342344.py). These are the recovered files.
  • `find recovered_files/py/ -type f -print0 | xargs -0 grep “class UserProfile:”` This is so that we can narrow it down to the files we want from the recovered files. We cannot use a regular grep because there might be too many files and you will get: /bin/grep: arg list too long
  • For more details checkout the foremost tool.

    Entry filed under: Software & Design, Ubuntu. Tags: , , , , .

    Stupid or Not: A Bubble/Jail Filesystem for Chrome Extensions Big O

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Connecting to %s

    Trackback this post  |  Subscribe to the comments via RSS Feed


    A blog about what matters, and what doesn't.
    This DailyGirl is an engineer who likes flowers and software, in that order.
    I am into tech, arts and the meaning of life. I am currently a software engineer at IBM in San Jose, California.

    Recent Posts

    Tweets

    Del.icio.us

    Flickr Photos

    Sublime Editor

    Sublime Editor

    Untitled

    Untitled

    DSC02530

    DSC02620

    More Photos

    Follow

    Get every new post delivered to your Inbox.