Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count number of files within a directory in Linux? [closed]

Tags:

linux

ls

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 wc ?

like image 477
Kantura Avatar asked Jan 03 '14 02:01

Kantura


People also ask

How do I count the number of files in a directory?

To determine how many files there are in the current directory, put in ls -1 | wc -l. This uses wc to do a count of the number of lines (-l) in the output of ls -1.

What is wc in Linux command?

wc (short for word count) is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count.


1 Answers

this is one:

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

Note:

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.

like image 147
Sajad Karuthedath Avatar answered Sep 22 '22 13:09

Sajad Karuthedath