Ubuntu – When counting lines with wc, don’t print an error whenever is a directory

wc

I want to count the total number of lines in all /etc files but not the files in the sub directories, so I typed: wc -l /etc/* | tail -1 and the output is like:

xxxx is a directory 
yyyy is a directory
total 1752

My question is, how can I rid of (delete) these comments, and is there a better way to do this type of count?

Best Answer

You can output the error messages to /dev/null

$ wc -l /etc/* 2>/dev/null | tail -1

With this command you are only seeing the number of lines in the files that are world readable. To see the number of lines of all the files you would have to elevated the command with sudo.

$ sudo wc -l /etc/* 2>/dev/null | tail -1