Derek Derek - 1 year ago 87
Linux Question

Count number of files within a directory in Linux (not using wc)

To count the number of files in a directory, I typically use

ls directory | wc -l

But is there another command that doesn't use

Answer Source

this is one:

ls -l . | egrep -c '^-'


ls -1 | wc -l

Which means: ls: list files in dir

-1: (that's a ONE) only one entry per line. Change it to -1a if you want hidden files too

| : pipe output onto...

wc: "wordcount"

-l: count lines.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download