Moving Files and Folders Accidentally to Non-existent Places

Léo Léopold Hertz 준영 picture Léo Léopold Hertz 준영 · May 1, 2009 · Viewed 14k times · Source

I often do the command such as:

mv folder $something_that_does_not_exist
mv files* $something_that_does_not_exist

Then, I realise that my files are gone. I cannot see them even in the folder "$something_that_does_not_exist". Where have my files and folders gone? How can I get them back?

Answer

Greg Hewgill picture Greg Hewgill · May 1, 2009

In order to prevent this problem, I have a habit of always appending a / to the end of directory names when using cp or mv:

$ touch foo
$ mv foo bar/
mv: cannot move `foo' to `bar/foo': No such file or directory

Without the trailing slash, mv does a file rename operation. You may find that your file(s) have changed name.