I need to count the number of files under a folder and use the following command.
cd testfolder
bash-4.1$ ls | wc -l
6
In fact, there are only five files under this folder,
bash-4.1$ ls
total 44
-rw-r--r-- 1 comp 11595 Sep 4 22:51 30.xls.txt
-rw-r--r-- 1 comp 14492 Sep 4 22:51 A.pdf.txt
-rw-r--r-- 1 comp 8160 Sep 4 22:51 comparison.docx.txt
-rw-r--r-- 1 comp 903 Sep 4 22:51 Survey.pdf.txt
-rw-r--r-- 1 comp 1206 Sep 4 22:51 Steam Table.xls.txt
It looks like ls | wc -l
even counts the total 44
as a file, which is not correct.
wc -l
is working as it should. Please run the commandtype ls
and report what you see. – John1024 Sep 05 '16 at 04:11wc -l
counts the number of lines... it's including the line that saystotal 44
. – cutrightjm Sep 05 '16 at 04:23