LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   replacing folder with mv command (https://www.linuxquestions.org/questions/linux-newbie-8/replacing-folder-with-mv-command-650364/)

bashyow 06-19-2008 12:57 PM

replacing folder with mv command
 
yow,

when i try to move the pictures folder from my camera to my home dir, i use this command

Code:

mv -f /mnt/camera/picfolder ~/
i get this error

Quote:

inter-device move failed, unable to remove target: Is a directory
now, you may have guessed that a folder of the same name already exists in the home dir, and this is part of the problem, but im wondering why the above commandline does not work and simply overwrite the old folder and its pix with the new folder/pix?

lleb 06-19-2008 01:04 PM

typically a -r or -R are used for recursive. try one of those to move the directory. or just cp -r

bashyow 06-19-2008 01:11 PM

-r -R

seem to be invalid options for the mv command.

colucix 06-19-2008 01:30 PM

You can try to copy the content of the source directory into the destination directory, then - if succeed - remove the original, for example:
Code:

cp -R /mnt/camera/picfolder/* ~/picfolder
but it is not clear which subfolder already exists in the home directory, so review the command line above to achieve your result.

bashyow 06-19-2008 02:55 PM

thankyou lleb and colucix.

i did have to use some 'cp' and 'rm' commands in the script instead of the 'mv' command, but its not a big deal, i just wonder why the move command doesnt do all that for me.

ah well, i did achieve what i wanted, so i guess thats the main thing.

ischi 06-19-2008 03:19 PM

The problem here is that the move is across 2 devices, the way mv works (and also way -r Options are not used and/or needed) is by replacing the node in the inode table (first sectors of your drive) which points to the folder by the new one, so actually as long as you stay on the same device no data is actually copied, but only the pointer to it is moved. I'm not going to go in more detail now... If you want to know more check out books about OS/Unix.
Now if you try to move a folder across 2 devices this cant obviously be done but Data has to be moved. So mv has to fall back on actually copying data from one device to another and removing it afterwards, and it cant remove the inode to which to copy because if it would remove it theres nothing to copy to, and if it doesnt remove it it cant copy to it because there is still data there (in short and dirty said ;) ). So thats why you cant mv and hav to copy.

For more info I would check Andrew S. Tannenbaum - Modern Operating Systems :)

Hope I could clear up your confusion a little

bashyow 06-19-2008 04:58 PM

i always suspected the concept of the pointer moving, and not the actual file, because when you move a big file to another part of the file system, its almost instant and theres no sound from the HD. i find that pretty cool :cool:

thankyou for your more indepth explaination ischi :)

Xeratul 11-30-2010 09:29 PM

Quote:

Originally Posted by colucix (Post 3189554)
You can try to copy the content of the source directory into the destination directory, then - if succeed - remove the original, for example:
Code:

cp -R /mnt/camera/picfolder/* ~/picfolder
but it is not clear which subfolder already exists in the home directory, so review the command line above to achieve your result.

I have read that -b could be use also into mv -b -f -v command ... right?

aliqasemi 09-06-2012 04:26 AM

Quote:

Originally Posted by ischi (Post 3189654)
The problem here is that the move is across 2 devices, the way mv works (and also way -r Options are not used and/or needed) is by replacing the node in the inode table (first sectors of your drive) which points to the folder by the new one, so actually as long as you stay on the same device no data is actually copied, but only the pointer to it is moved. I'm not going to go in more detail now... If you want to know more check out books about OS/Unix.
Now if you try to move a folder across 2 devices this cant obviously be done but Data has to be moved. So mv has to fall back on actually copying data from one device to another and removing it afterwards, and it cant remove the inode to which to copy because if it would remove it theres nothing to copy to, and if it doesnt remove it it cant copy to it because there is still data there (in short and dirty said ;) ). So thats why you cant mv and hav to copy.

For more info I would check Andrew S. Tannenbaum - Modern Operating Systems :)

Hope I could clear up your confusion a little

This make sence, but I still don't understand why it doesn't leave the destination folder intact and continue on moving the sub-folders/files, like when we copy using nautilus using the "merge" option. I guess it has been someting too modern to implement!


All times are GMT -5. The time now is 09:01 PM.