Skip to content

Recursively Count Number of Files within a Directory in Linux

On this page

Sometimes we need to find actual number of files available under a directory. But it directory contains multiple sub directories. Then it is hard to manually count number of files within a directory in Linux system using command line.

find DIR_NAME -type f | wc -l
  • find – Is a Linux/Unix command
  • DIR_NAME – A directory path to search for. Use dot (.) to start search from current directory
  • -type f – Search for files only (do not include directories)
  • Pipe (|) – Pipe sends output of one command as input to other command
  • wc -l – Count number of lines in result

Count files within current directory

Use the following command to count the number of available files under the current directory. Here dot (.) denotes to the current directory.

find . -type f | wc -l

Recursively Count Number of Files

Count files in specific directory

To count files under any other directory use the following command. Here the command will find all files under the /backup directory and print total count on screen.

find /backup -type f | wc -l

Recursive count files in linux command

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top