1826214 Members
2557 Online
109691 Solutions
New Discussion

Re: Copy Files

 
zap_2
Advisor

Copy Files

Hi unix gurus, how to copy folder and its subfolders include their files that rest in them to the new destination folder?Thanks in advance.
9 REPLIES 9
MarkSyder
Honored Contributor

Re: Copy Files

tar cvf /new_dir/old_dir.tar old_dir

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Biswajit Tripathy
Honored Contributor

Re: Copy Files

cp -r /old_dir /new_dir

- Biswajit
:-)
MarkSyder
Honored Contributor

Re: Copy Files

I forgot to mention that after you've created the tar file you need to:

cd /new_dir
tar xvf old_dir.tar

but if the directory is small, the cp suggestion you've received is just as good.

Mark
The triumph of evil requires only that good men do nothing
Leif Halvarsson_2
Honored Contributor

Re: Copy Files

Hi,
I prefer find/cpio for that task:

find . -print |cpio -pdvmux
harry d brown jr
Honored Contributor

Re: Copy Files

on the SAME machine??

"mv"

mv OLDfolder NEWfolder

live free or die
harry d brown jr
Live Free or Die
Stuart Abramson
Trusted Contributor

Re: Copy Files

Definitely the cpio method.

tar will work also.

the "cp" should NOT be used. If you have links the cp will follow the link and copy files NOT in the directory, but pointed to by the links.

1. cd /dir
find . -depth -xdev -print | cpio -pdum /newdir

where: /newdir already exists!

2. cd /fromdir
tar cf - . | (cd /todir; tar xf - )


C. NOTE: When copying, the copy seems to go faster when you have
"cleaned" off the target file systems. If data exists, he tries to
fit the new data in with the old (searching inode tables, etc.).
If the new file system is clean, he just writes the data out. Faster.
Geoff Wild
Honored Contributor

Re: Copy Files

As Harry mentioned - mv works great....

If it's filesytem based - vxdump is good as well:

vxdump -0 -f - -s 1000000 -b 16 /currentmount | (cd /newmount ; vxrestore rf -)

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Biswajit Tripathy
Honored Contributor

Re: Copy Files

Stuart Wrote:
> the "cp" should NOT be used. If you have links the
> cp will follow the link and copy files NOT in the
> directory, but pointed to by the links.

From cp(1) manpage for option '-R', it says the
following:

...Symbolic links are copied so that the target points
to the same location that the source did.

I thought that's what the user wanted to do.

- Biswajit
:-)

Re: Copy Files

I think that my reply to the following post may help you (look at the "Local" part).

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=837512&admit=716493758+1111188312291+28353475

You may also want to look at the attached file (in the same post), for alternatives.

Regards,

Alex