Unix cp argument list too long
Asked Answered
S

7

24

I am using AIX.

When I try to copy all the file in a folder to another folder with the following command:

cp ./00012524/*.PDF ./dummy01

The shell complains:

ksh: /usr/bin/cp: 0403-027 The parameter list is too long.

How to deal with it? My folder contain 8xxxx files, how can I copy them very fast? each file have size of 4x kb to 1xx kb.

Stent answered 5/5, 2011 at 3:31 Comment(2)
Possible duplicate of Argument list too long error for rm, cp, mv commandsHaematinic
Run "ulimit -S -s unlimited" command. Then perform cp/mv/rm operationAdjure
A
28

Use find command in *nix:

find ./00012524 -type f -name "*.PDF" -exec cp {} ./dummy01/ \; -print
Adaline answered 5/5, 2011 at 3:44 Comment(1)
In the general case, I would also add a "-type d". Directories matching */PDF should be rare, but for more general copy, it will avoid multiple copies resulting from copying first the parent directory (or failing at it without the -r flag) then the children.Pride
C
6

The cp command has a limitation of files which you can copy simultaneous.

One possibility you can copy them using multiple times the cp command bases on your file patterns, like:

cp ./00012524/A*.PDF ./dummy01
cp ./00012524/B*.PDF ./dummy01
cp ./00012524/C*.PDF ./dummy01
...
cp ./00012524/*.PDF ./dummy01

You can also copy trough find command:

find ./00012524 -name "*.PDF" -exec cp {} ./dummy01/ \;
Contestant answered 29/8, 2014 at 16:49 Comment(1)
I'm getting omitting directory './00012524' with the find command.Thistly
P
2
$ ( cd 00012524; ls | grep '\.PDF$' | xargs -I{} cp {} ../dummy01/ )
Pansypant answered 5/5, 2011 at 7:3 Comment(0)
P
1

The -t flag to cp is useful here:

find ./00012524 -name \*.PDF -print | xargs cp -t ./dummy01

Patrica answered 5/5, 2011 at 18:40 Comment(0)
S
1

The best command to copy large number of files from one directory to another.

find /path/to/source/ -name "*" -exec cp -ruf "{}" /path/to/destination/ \;

This helped me a lot.

Scrappy answered 18/2, 2014 at 19:58 Comment(1)
cp: illegal option -- uOpen
C
0

You should be able use a for loop, e.g.

for f in $(ls ./00012524/*.pdf)
do
    cp $f ./dummy01
done

I have no way of testing this, but it should work in theory.

Citole answered 5/5, 2011 at 3:45 Comment(2)
The ls command will probably (read "almost certainly") get the same error. Argument too long is a standard error from the C libraries on a Unix like system (man sysconf for more on that). The best appproaches are find ... | cpio -pvumd ... or using xargs or tar c...| tar x etc. NOne of those will need a shell expanded glob which is the cause of his problem. This is really more appropriate for SeverFault or SuperUser than for SO.Panhellenic
Improved version: for f in ./00012524/*.pdf; do but find+xargs+cp -t is much faster.Pumphrey
J
0

you can do something like this and grab each line of the directory


# you can use the -rv to check the status of the command verbose

for i in /from_dir/*; do cp -rv "$i" /to_dir/; done

Jarietta answered 19/4, 2021 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.