0

I have a folder with 5000 files that I want to copy somewhere else.

When I do cp ../folder* ., I get the following error:

-bash: /bin/cp: Argument list too long

However, getconf ARG_MAX returns 262144.

$ echo ../folder* |wc
1 5015 69144

Is this normal? I had been able to copy all those files before.

slm
  • 369,824

1 Answers1

4

Use a program to iterate over the arguments:

e.g. find .. -type d -iname '*/folder*' -exec cp -a {} . \;

of manually iterate with a loop, such as:

for myDir in ../folder* ; do cp -a "$myDir" . ; done

There are many other ways, but one of the above should do the trick for you. (The for-loop example might be slower)

  • wouldn't find ... -exec cp ... + run into the very same problem of having too many arguments as find will batch the output or is there a limit for batching size with +? – FelixJN Aug 11 '15 at 07:52
  • @Fiximan : I would consider it a bug in "find", if it offered "+" to batch arguments, without checking local system argument count limits. And since "find" is ancient software, they should have thought about, and fixed any bugs in this functionality decades ago. – Alex Stragies Aug 11 '15 at 08:21