Skip to content
Advertisement

Is it possible to somehow undo the results of the mv command?

Here’s the problem. I had a bunch of files in a directory. Then I created another directory in that directory. Then I cobbled together this command:

find . -maxdepth 1 -type f -exec mv {} ./1 ;

This command was supposed to take all the files in the directory and move them to that newly-created directory, but instead of providing the name of the directory, I screwed up and typed 1, as you can see from the code snippet. So, I ended up having just one text file named 1 that now contains the stuff from one of the disappeared files and that’s all.

Is there any chance I could recover the lost files (or possibly the actual data from the files–they were all text files) or are they pretty much permanently gone?


Before:

misha@hp-laptop:~/Documents/prgmg/work$ ls
add.s  bubble.s  cpuid.s  div.s    hello.s  mult.s       sum.s   test.s
a.out  c         demo.s   gas.txt  max.s    print_arr.s  test.c
misha@hp-laptop:~/Documents/prgmg/work$ mkdir asm

After:

misha@hp-laptop:~/Documents/prgmg/work$ ls
1  asm  c

So, as you can see, I wanted to put all assembly language files into the asm directory. And as things stand now, 1 is a text file and it contains the stuff from gas.txt.

Advertisement

Answer

No. Not easily. Sorry.

Restoring from backup would be the best option.

See the answers to the question “Recovering accidentally deleted files” over at Unix & Linux, if you feel like doing a bit of low-level file access.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement