Operating System - HP-UX
1826076 Members
2171 Online
109690 Solutions
New Discussion

Re: Copy large number of files using cp command

 
Roy Fernando
Occasional Contributor

Copy large number of files using cp command

Hi

I want to copy large number of files within one directory to another directory. When I am going to copy I am getting error message saying that list is too large. Is there a limitaion within cp command. How can I get arround from this problem.
9 REPLIES 9
Andreas Voss
Honored Contributor

Re: Copy large number of files using cp command

Hi,

the restriction is not the cp command but the shell itself.
Use the cpio instead:

cd
ls | cpio -pmdv

This will copy all files in to

If you want to copy a full tree (with subdirs) you can use:

cd
find . -depth | cpio -pmdv

Greetings

Andrew
surendhar prakash.J
Frequent Advisor

Re: Copy large number of files using cp command

Hi

To copy all files and subdirectory to target directory by using cp with -r option.

syntax as follows...

#cp -r /data /data1

(Here all files and subdirectory will be copied in to /data1 directory)

You can Help page for "cp" command use #man cp


by
suren
James Odak
Valued Contributor

Re: Copy large number of files using cp command

If you are running with low resources try this
cd dir
dir=the dir you want to copy all files from

ls > /tmp/somefile
for X in `cat /tmp/somefile`
do
cp $X newdir
echo copying $X
done

newdir being the new directory you want to copy to

good luck
Alan Riggs
Honored Contributor

Re: Copy large number of files using cp command

These solutions all work for copying files. For a general solution to use when you will generate a command list that exceeds the shell's buffer, look at piping to xargs.
Rick Garland
Honored Contributor

Re: Copy large number of files using cp command

If there are subdirectories within the directory;

cd to directory
find . -depth | cpio -pmuldv /newpath

This will keep the permissions the same and create the needed subdirectories with the files.
Harm Meijer
Occasional Contributor

Re: Copy large number of files using cp command

Just to add another trick to the list

cd to the source directory and then:

# tar cf - . | ( cd dest-dir ; tar xf - )

Cheers,

Harm
Yesterday it worked, today it doesn't. Windows is like that
Mike Stroyan
Honored Contributor

Re: Copy large number of files using cp command

The limit on the number of arguments can be
increased on series 700, HP-UX 10.20. The
default limit was 20478 bytes total for
environment variables and command
arguments. If you apply patch PHKL_16750 and set the tunable kernel parameter
large_ncargs_enabled to 1, then the limit
will increase to 2048000 bytes.
That larger limit is the default for 11.0.
Dhanesh Patel
Occasional Advisor

Re: Copy large number of files using cp command

and another way:
-------------------------------------------
cd sourcedir
find . -name '*' -exec cp {} /targetdir ;
-------------------------------------------

also good for removing large numbers of files from a directory:
--------------------------------------------
find . -name 'xxx*' -exec rm {} ;
--------------------------------------------
RDCanada
New Member

Re: Copy large number of files using cp command

Hi,

Did you get this working, or is it a ulimit problem?