Operating System - HP-UX
1822496 Members
2494 Online
109642 Solutions
New Discussion юеВ

copy files from one directory to another.

 
lin.chen
Frequent Advisor

copy files from one directory to another.

Can I copy files from one directory to another , keeping the permission and UID,GID?

there are many files ,how can I use command?
thanks a lot!
8 REPLIES 8
Pete Randall
Outstanding Contributor

Re: copy files from one directory to another.

There are many ways to do this, the simplest is to use cp with the -p option. You could also use find piped to cpio.

It all depends on whether you want to copy all the files or just some of them and, if just some, what the selection criteria may be.


Pete

Pete
lin.chen
Frequent Advisor

Re: copy files from one directory to another.

Pete,thanks alot!I just want to copy all the files from one directory to another.
It seem "cpio" can not support files more than 2G.
Does cp -p can preserve UID and GID?

Is following right?
#find . |cp -p /data
Uday_S_Ankolekar
Honored Contributor

Re: copy files from one directory to another.

cp -p will keep the permission UID/GID intact.
I would rather prefer cpio if there are multilple files to be copied.

cd /sourcedirectory

# find .|cpio -pudlmv /destinationdirectory

-USA..
Good Luck..
Bill Hassell
Honored Contributor

Re: copy files from one directory to another.

cpio (and tar) are not useful for large files (dozens of Gb) and cannot be used. cp works with all filesizes. Your question:

> Is following right?
> #find . |cp -p /data

No, you just use cp:

cd /old-directory
cp -p * /data

If there are thousands of files in that directory, you may get a line too long message. xargs will be required in that case. If you have any dot files (files starting with .), you'll need to copy those with something like this:

cp -p * .??*

This prevents copying the .. directory. There are other special filenames you will have to handle manually such .a .b .1 .2 and so on. Be careful of expression that match ..


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: copy files from one directory to another.

Hi:

If you have largefiles, I'd use 'fbackup' and 'frecover':

# cd /srcdir
# fbackup -i . -f - | (cd /dstdir; frecover -Xsrf -)

Regards!

...JRF...
John Guster
Trusted Contributor

Re: copy files from one directory to another.

use your backup software, backup, then restore...much quick, no worry about size of files, or permission changging etc. Cheers
Dennis Handly
Acclaimed Contributor

Re: copy files from one directory to another.

>Bill No, you just use cp:
cd /old-directory; cp -p * /data
>If there are thousands of files in that directory

Why not use "cp -pR /old-directory /new-directory"

The only issue is that new-directory can't exist. If is does, you'll have to move the files after you copy it. That should be easier than worrying about "." files. You still may have to use xargs for the mv.
KapilRaj
Honored Contributor

Re: copy files from one directory to another.

I would prefer ,

cd /source_dir
tar cvf - . |ksh "(cd /destination_dir;tar xvf -)"

Regards,

Kaps
Nothing is impossible