Unix cp argument list too long

倾然丶 夕夏残阳落幕 提交于 2020-05-12 11:43:09

问题


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.


回答1:


Use find command in *nix:

find ./00012524 -type f -name "*.PDF" -exec cp {} ./dummy01/ \; -print



回答2:


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/ \;



回答3:


$ ( cd 00012524; ls | grep '\.PDF$' | xargs -I{} cp {} ../dummy01/ )



回答4:


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.




回答5:


The -t flag to cp is useful here:

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




回答6:


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.



来源:https://stackoverflow.com/questions/5892339/unix-cp-argument-list-too-long

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!