I accidently ran sudo rm *

I thought I was in an unimportant subfolder.

The result is that I deleted some very important files. Is there any way to get my data back?

  • Witch type of file system is on partition?
    – 2707974
    Apr 2, 2015 at 7:16
  • @2707974 ext4
    – user284234
    Apr 2, 2015 at 7:20
  • 1
    use this answer.
    – 2707974
    Apr 2, 2015 at 7:23

2 Answers 2


But I prefer foremost

Install foremost

sudo apt-get install foremost

Take a look at

man foremost

to learn how to use foremost.

First make an empty writable directory to save recover files in a partition other than that you are going to recover.

Then run foremost.

I am going to recover my home partition ( let's say /dev/sda5).

$ sudo foremost -t jpg -i /dev/sda5 -o /recovery/data

Finally set user permission to /recovery/data/ to view image. type

$ sudo chown YOUR_USER_NAME /recovery/data -R

Some important foremost command line arguments.

-i  :- partition/image to recover
-o :- location to store recovered files.
-t  :- built in file filter options.  you can give multiple filters by separating using commas. (e.g: for jpg and pdf: -t jpg,pdf ) 
-q :- quick mode.
  • Can it recover bash scripts?
    – Dark Star1
    Jul 28, 2016 at 11:56
  • Probably yes. Run command without type of files -t.
    – 2707974
    Jul 29, 2016 at 6:50

After the steps from @2707974 above, then you can use this bash utility lines to browse millions of files quickly and painless, something like this:

`$ mkdir /recovery/filtered && cd /recovery/data && SKIP=1300 #SKIP value depends on your needs
$ for((j=$SKIP; j<10000; j=j+100)); do
   for i in $(ls -S . | head -n $j | tail -n 100); do
     cp $i ../filtered/;
   sleep 10;
   rm ../filtered/*;

And then now, you can open /recovery/filtered on your file browser, and watch your history...