How to cat when "Argument list too long"?

This is probably something super basic but any help would be appreciated.
I am trying to cat a list of list ~ 203900 files into one but I get an error message of "argument list too long". I did tried to look some solutions in the web but I only found this for cp.

find ./ -type f -name "*.txt" -print > /tmp/files.list
cat ​/tmp/files.list | xargs -I {} cp -uf {} /path/carpet/

Any ideas for cat?

Thank you in advance
Anaid

You need something like the following:

find . -type f -name "*.txt" -exec cat {} +
1 Like

@AnaidG do you really need the list file or do you just want to copy the files?
With the option -n N you can tell xargs that it should use a maximum of N arguments at once. Or you can use -exec to copy (no list file needed):

find -type f -name "*.txt" -exec cp -uf {} /path/carpet \;

@bendingrodriguez I would actually like to make the cat of the files :slight_smile:

So in this case @MadeInGermany , I would just re-direct the output file, right?

find . -type f -name "*.txt" -exec cat {} + > file.txt

@AnaidG the error comes from the fact that xargs passes all file names to cp at once. You should use xargs -n N, see above.

According to the initial post the cp was found on the Web and has no problem (xargs is smart in finding the max args), but is no solution to the cat problem either.

Yes, but the output file itself should not be found. Name it not .txt or put it into a directory outside the start directory tree (e.g. > ../file.txt is outside).

@AnaidG ah sorry, i missunderstood your question.