1

( find -print0 | xargs -0 cat ) | wc -l (from How to count all the lines of code in a directory recursively?) prints the total number of lines in all files in all subdirectories. But it also prints a bunch of lines like cat: ./x: Is a directory.

I tried ( find -print0 | xargs -0 cat ) | wc -l &> /dev/null (and also 2> /dev/null and > /dev/null 2>&1) but the messages are still printed to the shell.

Is it not possible to hide this output?

( find -type f -print0 | xargs -0 cat ) | wc -l overcomes this problem, but I'm still curious why redirecting stderr doesn't work, and if there is a more general purpose way to hide errors from cat.

David Winiecki
  • 4,093
  • 2
  • 37
  • 39

2 Answers2

3

You need to redirect the stderr stream of the cat command to /dev/null. What you have done is redirected the stderr stream of wc. Try this:

( find -print0 | xargs -0 cat 2>/dev/null ) | wc -l
tkocmathla
  • 901
  • 11
  • 24
0

If you want find only to find “regular” files, you must use find -type f ….

By the way, if you want to calculate lines of code, you should take a look at ohcount.

lxg
  • 12,375
  • 12
  • 51
  • 73