LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Used mv to move folder, but where are the files? (http://www.linuxquestions.org/questions/linux-software-2/used-mv-to-move-folder-but-where-are-the-files-781075/)

kmacphail 01-09-2010 11:25 AM

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:

Quote:

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 11:31 AM

#man mv

your command should move source files to destination directory?

10110111 01-09-2010 11:35 AM

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

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

man find
.

amani 01-09-2010 11:47 AM

or try
#locate part-of-filename

10110111 01-09-2010 12:31 PM

Quote:

#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 02: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. http://www.cgsecurity.org/wiki/PhotoRec to install in fedora
Code:

yum install testdisk
Goodluck

pixellany 01-09-2010 03: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 09:51 PM

A safer option would have been to run
Quote:

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

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-09-2010 11:09 PM

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 06: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 06:28 PM

Quote:

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 02: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 02:15 AM

Quote:

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.

Evo2.

kmacphail 01-11-2010 06:06 AM

Evo2

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 04:31 PM.