You are here

17 January 2014

This snippet shows you how to count files, folders of both in Linux terminal. This is achieved by find and wc commands. Find finds files and folders recursively and wc counts bytes, characters or lines.

Source code viewer
  1. # Count only directories.
  2. find DIRECTORY -type d | wc -l
  4. # Count only files.
  5. find DIRECTORY -type f | wc -l
  7. # Count files and directories.
  8. find DIRECTORY | wc -l
Programming Language: Bash