How can I recursively count files in a Linux directory?
I found this:
find DIR_NAME -type f ¦ wc -l
But when I run this it returns the following error.
find: paths must precede expression: ¦
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This should work:
Explanation:
-type fto include only files.|(and not¦) redirectsfindcommand’s standard output towccommand’s standard input.wc(short for word count) counts newlines, words and bytes on its input (docs).-lto count just newlines.Notes:
DIR_NAMEwith.to execute the command in the current folder.-type fto include directories (and symlinks) in the count.Explanation of why your example does not work:
In the command you showed, you do not use the “Pipe” (
|) to kind-of connect two commands, but the broken bar (¦) which the shell does not recognize as a command or something similar. That’s why you get that error message.