0

I have a directory with an absurd number of files, which makes this nigh impossible to understand by inspection. But here's the situation:

cp giant_folder/pre* myfolder

It's crunching along and starts generating warnings like:

cp: warning: source file 'giant_folder/pre1234.txt' specified more than once

How can this happen?

1
  • That shouldn't be possible Commented Oct 31, 2023 at 23:39

1 Answer 1

1

You could replace cp with echo to see the expansions, but there's a better way of dealing with "an absurd number of files". Read man find xargs cp, and do something like:

find giant_folder -maxdepth 1 -type f -name 'pre*' -print0 | \
    xargs -0 -r cp -t myfolder

This will pack as many filenames as it can on a line, and execute as many cp commands as it needs. See xargs --show-limits </dev/null.

2
  • It doesn't explain the error, though, and if the error report is true then your code will still copy N files to M destinations, where M < N Commented Oct 31, 2023 at 23:41
  • I discovered that some files matching the wildcard were not copied either, but they aren't the ones referenced in the error messages. Mysterious to me. If the command line got too long, my understanding is that there should be an error because the destination folder would be cut off.
    – Mastiff
    Commented Nov 1, 2023 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .