how to undo move file in linux?
23,151
Solution 1
You can try using find to discover which files in ".." was modified at the time you made the erroneous mv, and then mv them in the right place again (using -exec find option for example).
Solution 2
You cannot 'undo' it easily other than by sorting out which files belong where and to move them back again. Alternatively, you could restore from a backup and then compare the files from the backup and the present system to help.
Solution 3
I don't think there's any. Same goes with rm
, which is different from trashing.
Solution 4
This happened to me today! but you need not panic. suppose "file.txt" is your file name.
- in linux command prompt, go to the directory from where you moved the file "file.txt"
(using
cd directory_name
) - type
ls -a
(lists all files & sub directories including hidden files and directories) - you will see that a copy of the file that you moved was saved as "file.txt~"
- now execute
mv file.txt~ file.txt
in command prompt. (this will move the automatically saved copy of your file back to your file)
That's it! you're good to go!
Related videos on Youtube
Author by
hxuanhung
Updated on September 17, 2022Comments
-
hxuanhung almost 2 years
I made a mistake when moving a set of file by this command mv src/* .. instead of mv src/* .
-
isomorphismes almost 12 yearsSee superuser.com/questions/279733/undo-an-rm-rf-command for some possible solutions.
-
-
hxuanhung almost 15 yearsThanks for your suggestion ! I use this command find ../* -mmin -5 -type f -exec mv '{}' . ; I saw that it mv all the file in parent directory include file're not modified. Do you have any ideas for this command ?
-
isomorphismes almost 12 yearsHey, it's not exactly true that there's nothing you can do to get a
rm
ormv
-ed file back. The (negentropic) bits are still there, arranged in the right sequence. Kust the pointer in the file allocation table is gone. It's not impossible but it is difficult to find the bits and put the pointer back.