Well, to give that cat
from the question a new home, this should do:
find . -type f -exec cat {} + | wc -l
It executes a cat
with the maximum acceptable number of filenames (+
) again and again and pipes everything to wc
. If you do not want to traverse subdirectories, a -maxdepth 1
has to be added to the find command, after the directory.
As an alternative, the --files0-from
option to GNU wc
could be used:
find . -type f -print0 | wc -l --files0-from=- | tail -1
This option makes wc
read not the contents but the filenames from stdin, separated by null characters. With -print0
, find
will print those filenames null-byte separated. As wc
will still print out line counts for every file, it is advisable to skip everything except the summary line at the end, hence the tail
.
Both solutions have the advantage that they will work in any locale, whereas @cas' solutions have to be adapted ('total' is 'insgesamt' in German, e.g.).
ls, cat, mv
and other commands have this limitations. As the error already tells you, you are providing too many arguments to thecat
command in this case. Usegetconf -a |grep MAX_ARG
to see the MAX_ARG value that applies to your kernel. – Valentin Bajrami Mar 1 '16 at 8:17