Count Files in Directory in Linux

Count Files in Directory in Linux

Directories can contain a lot of files. When working with filesystem, may need to determine how many files are in a given directory and subdirectories. This tutorial shows how to count files in directory in Linux.

To count files recursively in directory, use the find command to find files and wc command in order to count the number of files.

sudo find /etc -type f | wc -l

The -type option with value f is used to find only files.

In order to count files in the first-level directory, specify -maxdepth option with value 1 for find command.

sudo find /etc -maxdepth 1 -type f | wc -l

Leave a Comment

Cancel reply

Your email address will not be published.