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
- # Count only directories.
- find DIRECTORY -type d | wc -l
- # Count only files.
- find DIRECTORY -type f | wc -l
- # Count files and directories.
- find DIRECTORY | wc -lProgramming Language: Bash