If you need to count how many files are in a directory on Linux, then you can use a combination of the ls command to list all the files, and the wc command to count how many lines are printed:

Option 1 – Using wc

1
ls | wc -l

You can specify a directory as follows:

1
ls <directory> | wc -l

Option 2 – Using find

You can count files recursively by using the find command:

1
find <directory> -type f | wc -l

Option 3 – Using tree

Using the tree command will print out the amount of directories and files found, but if used in a large directory, then this will print a lot of output to the screen, so be careful with this one.

1
tree

This command will not count hidden files, so add the -a attribute to include them:

1
tree -a <directory>