1834648 Members
2504 Online
110069 Solutions
New Discussion

Moving Directories

 
Tony Williams
Regular Advisor

Moving Directories

I want to move some directories from one disk to another to alleviate disk space problems. I haven't done this in a while so I checked my notes and my notes say that I should use 'find . -name -depth -xdev | cpio -pdumv > /targetdir'. I would think that I should just be able to 'mv /sourcedir/* /targetdir'. I think I was told to use the find/cpio method so that all links would be followed and copied but I'm sure mv does the same thing.

Does anyone know if there is a reason not to use the mv command to move directories?

Thanks
4 REPLIES 4
RAC_1
Honored Contributor

Re: Moving Directories

mv will not copy the links. Also it is not good idea to user mv. If mv fails, it could create problems.

cp -rp source_dir target_dir

Will do link copy. man cp for details. You can also use find.

find . -type d -name "dir1" -depth -xdev | cpio -pudmv > /dest_dir
There is no substitute to HARDWORK
Pete Randall
Outstanding Contributor

Re: Moving Directories

The find | cpio technique is just going to copy the director contents and you have to go back to rm the original - kink of a safety net in case something goes wrong, whereas the mv, if you have problems with it, is going to leave you stranded.


Pete

Pete
TwoProc
Honored Contributor

Re: Moving Directories

leave off the "-name" argument - that's for searching for something that meets a named criteria. Leave off the ">" greater than. Unlike the other cases - when you invoke cpio with the -p command it knows that the next argument is a target directory - so you must leave off the ">" symbol.

Use:

cd /source_dir
find . -xdev -depth | cpio -pdmvu /destdir
We are the people our parents warned us about --Jimmy Buffett
Tony Williams
Regular Advisor

Re: Moving Directories

Excellenet responses thanks for all the info, I am definitely using find.