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:

ls /var/css | wc -l

Here, /var…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Johnny Simpson

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:

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

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


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Johnny Simpson


Print Share Comment Cite Upload Translate Updates
APA

Johnny Simpson | Sciencx (2022-10-01T17:48:50+00:00) How to count all files in a directory in Linux. Retrieved from https://www.scien.cx/2022/10/01/how-to-count-all-files-in-a-directory-in-linux/

MLA
" » How to count all files in a directory in Linux." Johnny Simpson | Sciencx - Saturday October 1, 2022, https://www.scien.cx/2022/10/01/how-to-count-all-files-in-a-directory-in-linux/
HARVARD
Johnny Simpson | Sciencx Saturday October 1, 2022 » How to count all files in a directory in Linux., viewed ,<https://www.scien.cx/2022/10/01/how-to-count-all-files-in-a-directory-in-linux/>
VANCOUVER
Johnny Simpson | Sciencx - » How to count all files in a directory in Linux. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/01/how-to-count-all-files-in-a-directory-in-linux/
CHICAGO
" » How to count all files in a directory in Linux." Johnny Simpson | Sciencx - Accessed . https://www.scien.cx/2022/10/01/how-to-count-all-files-in-a-directory-in-linux/
IEEE
" » How to count all files in a directory in Linux." Johnny Simpson | Sciencx [Online]. Available: https://www.scien.cx/2022/10/01/how-to-count-all-files-in-a-directory-in-linux/. [Accessed: ]
rf:citation
» How to count all files in a directory in Linux | Johnny Simpson | Sciencx | https://www.scien.cx/2022/10/01/how-to-count-all-files-in-a-directory-in-linux/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.