Help with cat long list of file

I have long list of input file's content that I plan to "cat" all of the content into another output file.
The total input file is around 20,000 which all named with ".txt"
Below is the command that I try:

cat *.txt > all_file.out
-bash: /usr/bin/sudo: Cannot allocate memory

Unfortunately, it shown the above error message.
can I know how to solve it out?
Many thanks for advice.

 
for filename in *.txt
do
    cat $filename >> all_file.out
done
1 Like
echo *.txt | xargs cat >OUTPUTFILE

or (if filenames contain spaces):

find . -name '*.txt' | xargs cat
1 Like