How do I use ls to get the number of files in a directory and all the directories beneath it?
Page 1 of 1
Counting files with ls
#2
Posted 05 May 2006 - 07:32 PM
I didn't try this yet but maybe try this guy's suggestion: web page
My disclaimer: 1) There's an old saying in unix "not can you do something in unix - but how can I do it in unix... 2) Please take unix seriously - When I was first starting out using AIX (a variation of unix) I succeeded in erasing an entire hard drive but playing with the scripts out of the books ... don't treat unix like windoze and hope for the best ... try to see what the commands/scripts are doing (work through them and then and only then execute them).
My disclaimer: 1) There's an old saying in unix "not can you do something in unix - but how can I do it in unix... 2) Please take unix seriously - When I was first starting out using AIX (a variation of unix) I succeeded in erasing an entire hard drive but playing with the scripts out of the books ... don't treat unix like windoze and hope for the best ... try to see what the commands/scripts are doing (work through them and then and only then execute them).
#4
Posted 06 May 2006 - 06:26 AM
code:
ls | wc -l
works well for a directory with no subdirectories, but if I do
code:
ls -R | wc -l
it counts all the subdirectories, and blank lines in the output of ls. Can I use grep or something to exclude any blank lines, or those starting with ./?
Actually, I'm not sure exactly what wc is counting:
code:
$ ls -R
dir1 dir2 file1 file2 file3
./dir1:
file1 file2
./dir2:
file1 file2
$ ls -R | wc -l
13
Page 1 of 1



Sign In
Register
Help


MultiQuote