• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Source Digit

Source Digit

Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • How To
  • Ubuntu
  • Instagram
  • Blogging
  • Android
  • WordPress
  • +More
    • Cloud Computing
    • Gadgets
    • Social Media
    • Technology
  • Write for Us
Home / How To / Count And Find Number Of Files In A Linux Directory

Count And Find Number Of Files In A Linux Directory

By Sourabh / July 18, 2025 Category: How To, Ubuntu

How to find number of files in a directory in Linux? There are many commands to find the total number of files in a directory on a Linux Ubuntu System.

Linux Command To Find Number Of Files In A Directory And Subdirectories

Command 1: Use ls and wc command
Command 2: Use tree command
Command 3: Use find command

1. Using ls and wc Commnad

The simplest command to count number of files in a directory and subdirectories is ls and wc command. To use it, simply run:

ls | wc -l

The wc counts the number of bytes, characters, whitespace-separated words, and newlines in each given file.

The ‘wc’ command prints one line of counts for each file, and if the file was given as an argument, it prints the file name following the counts.

Note that when more than one files are given, ‘wc’ prints a final line containing the cumulative counts, with the file name ‘total’. The counts are printed in this order: newlines, words, characters, bytes, maximum line length.

The wc command is very different from ls command, the ‘ls’ lists information about files (of any type, including directories).

NOTE: When we run the command ls and wc with -l options, the command will count all the files and directories but not the hidden ones. To list the hidden files, use -A option with the ls command:

ls -A | wc -l

If you want to count the number of files, including hidden files, in the current directory, run the following set of command:

ls -Ap | grep -v /$ | wc -l

In the above command, -p with ls adds / at the end of the directory names.

The -A with ls option will list all the files and directories, including hidden files but excluding . and .. directories. Whereas wc -l counts the number of lines.

Recursively Count Files in Directory

Ubuntu Linux users can use find command to recursively count files in directory:

find DIR_NAME -type f | wc -l

Linux users can also use tree command for displaying the number of files in the present directory and subdirectories:

tree -a

If you want to get the number of files in the current directory only but not the subdirectories, set the level to 1:

tree -a -L 1

Linux Ubuntu users can execute find command to count the number of files in a directory: The find command will get all the files first and then count them using the wc command. Execute the following command:

find directory_path -type f | wc -l

If you don’t want to count the number of files from the subdirectories, limit find command at level 1. Note that level 1 is used for the current directory.

You can execute the following command:

find . -maxdepth 1 -type f | wc -l

For those who are not aware, the ‘find’ command searches the directory tree rooted at each file name.

This list of files to search is followed by a list of expressions describing the files we wish to search for.

Concluding the tutorial, I can say that the easiest way to count files in a directory is using the “ls” command with the “wc -l” command argument.

Primary Sidebar

Latest Posts

Delete Directory And Contents Recursively Without Prompt On Linux

Check User Login History In Ubuntu Linux Command Line

Use Locate Command To Find File In Linux Terminal By Name

How To Change Terminal Color In Ubuntu Command Line

How To Run Fsck Manually In Linux To Fix Unexpected Inconsistency

How To Fix Broken Packages On Ubuntu From Terminal

Re Execute The Previous Command In Linux Ubuntu Command Line

How Much RAM Is Needed For Ubuntu PC

How To Find Large Files And Directories In Linux Command Line

How To Use Clear Command History In Linux Terminal

© 2026 Source Digit • Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • About
  • Privacy Policy
  • Terms & Conditions
  • Contact Us
  • Sitemap