Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)

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

ls directory | wc -l

But is there another command that doesn't use the wc?

1 Answer

0 votes
by (36.8k points)
edited by

this is one:

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

Note:

ls -1 | wc -l

Which means: ls: list the files in dir

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

|: pipe output onto.

WC: wordcount

-l: the count lines.

Come and join Linux training to gain great knowledge. 

Do check out the video below

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 28, 2020 in Linux by blackindya (18.4k points)
0 votes
1 answer
asked Nov 26, 2020 in Linux by blackindya (18.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...