File Disappeared on Move – Command Line Fix

command linefilesmv

I had a directory with a file and another empty directory in it like this:

.
..
file.ext
folder

I did:

mv file.ext /folder

The file disappeared now, not in folder too not where it was before!

Anyway to find it back?

Thanks

Best Answer

If the directory /folder (under root directory, /) does not exist, and if you were working as root, you have renamed (moved) the file file.txt as folder under /.

Doing a ls -l /folder should show you the file.

Another point is, if a directory /folder does exist, then look under that directory for the file i.e. /folder/file.txt.

Also note that if you append a / to the destination path, you would get a different message like:

mv: cannot move ‘file.txt’ to ‘/destination/’: Not a directory

and the file will not be renamed.

For example:

% sudo mv file.txt /spamegg/
mv: cannot move ‘file.txt’ to ‘/spamegg/’: Not a directory

% sudo mv file.txt /spamegg 

% ls /spamegg  
/spamegg
Related Question