Last Updated: February 25, 2016
·
421
· flaviodesousa

wc for thousands of files

I was split/merging a huge set of log files and to check if everything went fine I tried:

ls /tmp/logs|xargs wc -l -c

Which gave me a sad:

zsh: argument list too long: ls

Poor ls couldn't handle it... so I tried:

find /tmp/logs -iname "*log" | xargs wc -l -c

But it broke the totalization several times. I think xargs limiting the size of the wc command line.

So I RTFM of wc and found this:

--files0-from=F
read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input

But... but... NUL-terminated?!?! Why not a common line file?

Well... Okay... find -printf argument FTW!

find /tmp/logs -iname "*log" -printf "%p\0"|wc --files0-from=- -l -c