0

This question already has an answer here:

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.

marked as duplicate by G-Man, Braiam, Anthon, Ramesh, cuonglm Aug 11 '15 at 1:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    ARG_MAX is a character limit, not an parameter count. – Jeff Schaller Aug 10 '15 at 18:01
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 +? – Fiximan Aug 11 '15 at 7: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 8:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.