Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to restore files/directories which are deleted from terminal using rm and rm -r?. If a file is deleted from graphical interface, it could be restored from trash, but how do you restore a file if it is removed using the rm utility?.

share|improve this question
for tools to recover deleted files (in any form), you can take a look at this question – Decio Lira Oct 16 '10 at 2:08

To this end I use trash-cli package and the following alias in my ~/.bashrc

alias rm=trash

The files you remove will be moved to trash, and you can see them in nautilus trashcan.

You can always access the real rm by using one of the following method:

command rm something
'rm' something
\rm something

There are also commands to access the trashcan from terminal, trash-list, trash-restore, trash-empty installable from package trash-cli (then see their man pages).

Last note, it is not advisable to use such an alias for super-user, because it can interfere with system operations.

share|improve this answer
It is a work-around, but does not really answer the question. – evgeny Oct 13 '10 at 7:09
I think the user also would to know if there is some method to achieve the same behavior from command line. If not, I am ready to remove my answer. – enzotib Oct 13 '10 at 7:18
It's good. I have gained some knowledge. – user3215 Oct 13 '10 at 8:05

Deleting it from terminal deletes it permanently - recovery is very hard and sometimes impossible.

If your partition type is ext3 (check it by using the System->Administration->Disk Utility), then take a look at ext3undel.

If it is not (if you installed Ubuntu with default settings), try the extundelete program.

There is no guarantee you will recover anything though.

share|improve this answer
It would be really useful for desktop editions. – user3215 Oct 13 '10 at 8:07

You are looking for: extundelete - utility to recover deleted files from ext3/ext4 partition

To find such a package, you can try: apt-cache search undelete

To use the utility install it with: sudo apt-get install extundelete

After installation invoke man extundelete and study it carefully.

share|improve this answer
I typed it in the terminal and this appeared: e2undel - Undelete utility for the ext2 file system extundelete - utility to recover deleted files from ext3/ext4 partition libnet-imap-simple-perl - Perl module to manage an IMAP account magicrescue - recovers files by looking for magic bytes recover - Undelete files on ext2 partitions testdisk - Partition scanner and disk recovery tool undbx - Tool to extract, recover and undelete e-mail messages from .dbx files ..but I don't know what to do next – cabbit Mar 9 '13 at 20:39
@piggy-boink see update – H.-Dirk Schmitt Mar 9 '13 at 20:43
Oh. thank you very much :D – cabbit Mar 9 '13 at 20:44

Sorry, but files deleted from a command-line with the "rm" and "rm -f" bypass the "Trashcan" you have on the Gnome desktop.

You may also want to ask if there are any extfs "undelete" tools like there are for FAT and NTFS. (I don't know of any, but I'd be surprised if there were none.)

share|improve this answer
Oh... it's ok!. I thought it could be recovered from some location. – user3215 Oct 13 '10 at 6:49

Just as an alternative, if you know specifically what type of file it is...

sudo apt-get install foremost

Now open up /etc/foremost.conf and you will see a long list of commented out lines. If your file type exists, uncomment the line (you may also want to remove the irrelevant lines).

If your file type does not exist, add your own line. Say I want to recover a .css file and I know its around 40K. I could do add this:

css     n       40000   Theme\sName:     Plugin\sFixes

The 2nd column refers to case-sensitivity, the third column refers to the upper limit for size, the 4th column is how the file starts (remember to use escaped characters) and the last column is how the file usually ends.

Use the following command (edit the disk accordingly. could check with df command)

foremost -v -T -c /etc/foremost.conf -i /dev/sda -o output

What will happen next is that foremost will create a folder called output and dump all the recovered data (in this case) into the folder. From there you could use diff or meld to compare the recovered 'files' and see which is the most up to date.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.