How to Count Files in a Directory on Linux

If you want to find out how many files are inside a folder before running any type of file processing script on it.

Using the find Command

The find command can locate files in a directory and its subdirectories. By piping the output to wc -l, you can count the number of files:

sh find /etc -type f | wc -l

This command:

Searches for all files (-type f) under /etc Pipes the list to wc -l to count the lines, which correspond to the number of files

Using the tree Command

The tree command provides a structured view of a directory and includes a summary with the total number of files and directories:

tree <directory>

At the bottom of the output, you'll see a summary showing the number of files and directories.


  • Audentes fortuna iuvat. — Virgil
  • Aut viam inveniam aut faciam. — Hannibal Barca
  • Inveniam viam aut faciam. — Seneca
  • Fortis cadere, cedere non potest. — Latin Proverb
  • Non ducor, duco. — Motto of São Paulo
  • Per aspera ad astra. — Latin Proverb
  • Si vis pacem, para bellum. — Vegetius
  • Acta non verba. — Latin Proverb
  • Vincit qui se vincit. — Latin Proverb
  • Temet nosce. — Latin translation of the Delphic maxim
  • Ignis aurum probat, miseria fortes viros. — Seneca
  • Tandem fit surculus arbor. — Latin Proverb
  • Faber est suae quisque fortunae. — Appius Claudius Caecus
  • Labor omnia vincit improbus. — Virgil
  • Gutta cavat lapidem, non vi, sed saepe cadendo. — Ovid
  • Semper fidelis. — Latin Motto
  • Dum spiro, spero. — Cicero
  • Invictus maneo. — Latin Proverb
  • Nec aspera terrent. — Latin Motto
  • Amor fati. — Friedrich Nietzsche
"> ');