-   Linux - Software (
-   -   Used mv to move folder, but where are the files? (

kmacphail 01-09-2010 12:25 PM

Used mv to move folder, but where are the files?
I have recently taken to using the command line more in order to gain more experience and increase my knowledge of the Linux systems.

I have a (pretty major maritally) problem. I moved the folders containing our pictures using the mv command:


mv /{original_position} /{new_position}
This appeared to work until I noticed that the folders only have been moved and there is no sign of the files in either the original source or destination.

Where have they gone and can I get them back?

Next time I'm copying them and deleting the source when I make sure they are safe!!!!

Well you learn from mistakes ;) but I really would like these back, if only to avoid deafness and a 20 year headache.

amani 01-09-2010 12:31 PM

#man mv

your command should move source files to destination directory?

10110111 01-09-2010 12:35 PM

If you know a filename of some of the files you lost, you could use find utility:

find /directory/to/start/search/from -name "your_file_name.ext"
or, for case-insensible search, change -name to -iname. For more info,

man find

amani 01-09-2010 12:47 PM

or try
#locate part-of-filename

10110111 01-09-2010 01:31 PM


#locate part-of-filename
Should have done updatedb for this to work... so find might be more efficient for one-time search.

highfructose327 01-09-2010 03:05 PM

Wow that is odd, maybe try testdisk/photorec to recover the images. I have used it to recover images that were deleted, it worked well. to install in fedora

yum install testdisk

pixellany 01-09-2010 04:23 PM

This aspect of a Linux (or any) filesystem should be pretty much deterministic.

Within one physical drive, a mv command will not actually relocate anything---it only changes the info used to get to the folder/files. As others have pointed out, the files will be recoverable. (Just don't write to the disk.)

I am curious about your description of the move: "mv /source /destination". You would not normally be moving files or folders at the root level like that. Can you post exactly where the folder was and exactly what command you used?

titetanium 01-09-2010 10:51 PM

A safer option would have been to run

cp -a /source /destination
and then compare them to make sure they are the same before deleting the /source directory. Even better:

tar -jvcf backup.tar.bz2 /source && cp -a backup.tar.bz2 /destination/ && cd /destination && bzip2 -dc backup.tar.bz2 |tar xvf -
That's just an example of what can be done.

David the H. 01-10-2010 12:09 AM

I suggest also using the -v option to provide verbose output, both for mv and cp. Set it up as an alias for it so that it becomes the default behavior. It would've probably told you instantly what happened.

You might also consider the -i option, which makes it ask you interactively before actually performing the move, although that can become tedious when you're operating on a large number of files at once. One compromise is to use -i for the first few files, then crtl+c terminate the command and re-run it for the rest of them without the interaction.

kmacphail 01-10-2010 07:21 PM

Well folks, thanks to everybody for the help and advice. I searched using parts of the file names, extensions but got nothing. However I did try photorec after a suggestion from highfructose327 and that has recovered my files. I will definitely copy my files from now on rather than moving them. Again thanks to everybody for their advice.

kmacphail 01-10-2010 07:28 PM


Originally Posted by pixellany (Post 3820533)
I am curious about your description of the move: "mv /source /destination". You would not normally be moving files or folders at the root level like that. Can you post exactly where the folder was and exactly what command you used?

I used the command as follows:

mv /home/kevie/pics /temp/

I was keeping the stuff I was wanting before cleaning out my home folder, I had previously made a folder called temp with the mkdir command. Like I said I am trying to use the command line more and have been consulting the Command Line and Shell Scripting Bible.

David the H. 01-11-2010 03:09 AM

There's no need to be afraid to use mv or to be overly-cautious with it. But you do have to watch what you're doing. I think the problem you had is mostly because the default action for many *nix tools is to work silently, without feedback. You just need to set things up to provide you with some interaction, gain some experience, and you'll be fine.

There's a package I recommend called removeutils. Two of the programs it contains are imv and icp, which work just like the standard mv and cp, but if you give them only a single file or directory argument it will place it in an edit buffer and let you simply rename it directly. I've found it very convenient and safer than the originals when renaming files and moving directory trees. You can set up aliases so that they can perform as substitutes for the core versions.

I still suggest using the interactive options, of course. :)

evo2 01-11-2010 03:15 AM


Originally Posted by kmacphail (Post 3821826)
I used the command as follows:

mv /home/kevie/pics /temp/

Just to check, whas it really "/temp/" or was it "/tmp/". If the latter did you reboot your machine? On many systems all files in /tmp/ will be deleted on a reboot.


kmacphail 01-11-2010 07:06 AM


I did make sure that I made the folder called "temp", I may not be that experienced but I am aware that if I moved files I needed to "tmp" that I would not see them in a hurry, that's why I used the "temp" folder as it was not native and does stick out a bit at root level.

David the H

Thanks I will look into that package.

All times are GMT -5. The time now is 03:33 PM.