Linux & MacOS: Counting Files In A Directory

PHP Developer Freelance | E-learning Platform external link
🔗 See other jobs

You can count the number of files in a directory with the wc command.

wc outputs the total number of newlines, bytes, and words.

To count the number of files and folders in a directory you need to pipe the ls command to the wc command :

01: ls | wc -l 
02: # example output: 115

The -l flag specifies that we only care about newline count. Which is a count of all files and folders listed out by the ls command.

NB: Since wc counts output on the screen, if your directory contains both folders and files, the folders will also be counted.

Here is another article you might like 😊 "Deploying a static website to AWS S3"