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


I did:

mv file.ext /folder

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

Anyway to find it back?


  • 2
    Were you working as root? if so, you probably just renamed file.ext to /folder (which would be a file in the filesystem root directory /): look there. – steeldriver Nov 16 '15 at 3:01
  • yes its there, now how to retrieve it? :) ?? – nabtron Nov 16 '15 at 3:12
  • ok renamed it ! voila! :) thanks! – nabtron Nov 16 '15 at 3:14
  • it doesn't matter if you are working as root or not, because there was a / in front of the folder name, it will go to / which is the root of your file system. – mchid Nov 16 '15 at 3:15
  • 1
    no mchid, it wouldn't go there, it would become that steeldriver is right, it became the file with name folder – nabtron Nov 16 '15 at 3:16

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  
  • I have a question, if I move the file somewhere other than / like at /folder/folder2/folder3 it doesn't become folder3, rather it creates a new folder3 if it doesn't exist already and then sits there? or will it do the same and become a file folder3 there too? – nabtron Nov 16 '15 at 3:20
  • @nabtron the rule is universal..if a directory exists the file will be copied into it and if the directory does not exist it will be named as the "directory" i.e. last component.. – heemayl Nov 16 '15 at 3:34
  • Unless you also end the path with a slash, eg /folder/folder2/folder3/... If that doesn't exist you'll see a mv: failed to access ‘...’: Not a directory – Oli Nov 16 '15 at 9:58

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.

  • no it wouldn't go in that folder, it would become a file named folder in / folder – nabtron Nov 16 '15 at 3:16
  • @nabtron only if the directory of that name did or does not exist would that happen – mchid Nov 16 '15 at 3:18
  • @nabtron and then, it would become a file named folder in / – mchid Nov 16 '15 at 3:19
  • yes, thanks for clarification :) – nabtron Nov 16 '15 at 3:21
  • does it happen for root only or for all? – nabtron Nov 16 '15 at 3:21

protected by Community Jan 16 '18 at 12:04

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.