This should work:
find DIR_NAME -type f | wc -l
-type fto include only files.
findcommand’s standard output to
wccommand’s standard input.
wc(short for word count) counts newlines, words and bytes on its input (docs).
-lto count just newlines.
.to execute the command in the current folder.
- You can also remove the
-type fto include directories (and symlinks) in the count.
- It’s possible this command will overcount if filenames can contain newline characters.
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.