File disappeared on move
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.
Related videos on Youtube
Comments
-
nabtron over 1 year
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
-
Admin over 8 yearsWere 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. -
Admin over 8 yearsyes its there, now how to retrieve it? :) ??
-
Admin over 8 yearsit 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.
-
Admin over 8 yearsno mchid, it wouldn't go there, it would become that steeldriver is right, it became the file with name folder
-
Admin over 8 yearssteeldriver please write it as an answer so that I can mark it as correct
-
Admin over 8 years@nabtron yes it would go there because that is the path
-
Admin over 8 yearswell i just checked and it was a file with name "folder" in /
-
Admin over 8 yearscan you please explain?
-
-
nabtron over 8 yearsno it wouldn't go in that folder, it would become a file named folder in / folder
-
mchid over 8 years@nabtron only if the directory of that name did or does not exist would that happen
-
mchid over 8 years@nabtron and then, it would become a file named folder in /
-
nabtron over 8 yearsI 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 over 8 yearsdoes it happen for root only or for all?
-
mchid over 8 years@nabtron when working as any user
-
nabtron over 8 yearsno i mean for root main directory or for any subdirectory too?
-
mchid over 8 years@nabtron Yes, you are right for all directories. My answer assumed there was a directory named folder in / already but since there was not I guess the file was renamed /folder.
-
heemayl over 8 years@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..
-
nabtron over 8 yearsyap! i appreciate your help!
-
Oli over 8 yearsUnless you also end the path with a slash, eg
/folder/folder2/folder3/
... If that doesn't exist you'll see amv: failed to access ‘...’: Not a directory