In this brief post, we'll learn to count number of files in current or any other folder on Ubuntu and Linux Mint with terminal.

Step 1: Count number of files in current folder

First example will show us how to the find the number of all files in the working directory:

find . -type f | wc -l

Result:

176

Explanation:

  • . - represents the current working folder
  • -type f - searching for files only. Use -type d - for folders
  • | wc -l - counts the output of the previous command

Note: This is counting only files and not including hidden ones. It will count the files in the subfolders recursively.

Step 2: Count number of files based on file type or name

If you like to get the number of the files only from a given file type or name pattern then you can use next command:

For .html files:

find . -type f -name *.html | wc -l

output:

0

Counting all CSV files in the current folder with terminal:

find . -type f -name *.csv | wc -l

output:

2

Where:

  • -name *.csv - gives a pattern for the name. It reads like - give me anything followed by .csv. If you like to search for filenames containing keyword in their name - *keyword*.

Step 3: Count number of files in folder

If you like to work with another folder different than the current one you can do it by:

find ~/Downloads/ -type f -name *.md | wc -l

Where ~/Downloads/ is the folder where the search will be performed.

count-files-directory-linux-mint.png