linuxbash

Recursively counting files in a Linux directory


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: ¦


Solution

  • This should work:

    find DIR_NAME -type f | wc -l
    

    Explanation:

    Notes:

    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.