Linux

How to count all files in a directory in Linux

Sponsor

Counting all files in Linux and Mac

To count all files in a directory in linux, simply cd to that directory and then run the following command:

shell Copy
ls | wc -l

Alternatively, you can select the directory by adding the directory to the command like so:

shell Copy
ls /var/css | wc -l

Counting all files in Window

To do the same thing on windows, use cd to move to the directory in question, and then run the following on command line:

shell Copy
dir

This will list all files and directories in a folder, and tell you how many files and directories exist.

Last Updated Friday, 19 November 2021

Subscribe to Newsletter

Subscribe to stay up to date with our latest web development and software engineering posts via email. You can opt out at any time.

Not a valid email