File disappeared on move

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


Solution 1:

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

Solution 2:

If you wanted to move the file to the folder in the same directory, you should have done this:

mv file.ext folder

However, because you have done this instead:

mv file.ext /folder

the file has been moved and renamed to /folder instead of folder/file.ext

.

Run the following command:

cd /

and then run:

ls | grep folder

and it should show up in the results.