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. The first snippet demonstrates how to count directories exclusively, narrowing down the search with the -type d option. Similarly, the second snippet provides a concise method for counting only files using -type f. The third snippet takes a broader approach, counting both files and directories without specifying the type. These commands offer a versatile toolkit for programmers and system administrators, providing a quick and effective means of assessing directory structures in the Linux environment. Whether you're managing files or gaining insights into your system's composition, mastering these commands enhances your command-line capabilities.
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