DEV Community 👩‍💻👨‍💻

Cover image for How to count all files in a directory in Linux
Johnny Simpson
Johnny Simpson

Posted on • Originally published at fjolt.com

How to count all files in a directory in Linux

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

ls | wc -l

Alternatively, you can select the directory by adding the directory to the command like so:
Enter fullscreen mode Exit fullscreen mode

ls /var/css | wc -l

Here, /var/css is the directory you want to count the files in.

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:

dir
Enter fullscreen mode Exit fullscreen mode

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

Latest comments (1)

Collapse
 
gitkat profile image
GitKat

cool

Want to Create an Account?
Now it's your turn!
 
🗒 Share a tutorial
🤔 Reflect on your coding journey
❓ Ask a question

Create an account to join hundreds of thousands of DEV members on their journey.