WOW, that was quick!
This has to be the record for returned summary but when I got Mark Anderson's
reply, I think that one will be hard to top.
Reply's"
Mark Anderson:
This will print the total number of files (including subdirectories,
since they are files too) in the current directory:
% ls | wc -l
If you don't want subdirectories, then exclude them:
% ls -F | grep -v '\/$' | wc -l
or
% ls -l | egrep -v '^d|^t' | wc -l
or
% expr `ls -l | grep -v '^d' | wc -l` - 1
Just why these work is left as an excercise for the student. ;-)
If you want the number left-justified, pipe it through awk:
ls -F | grep -v '\/$' | wc -l | awk '{print $1}'
The last step is to create an alias or shell script that will take an
argument (call the script fnum):
#!/bin/sh
ls -F $* | grep -v '\/$' | wc -l | awk '{print $1}'
Use it like this:
% fnum /usr/local/bin
Dave McFerren:
try
ls | wc -w
This returns the number of files that are listed by the ls command. If you also
want hidden files, try
ls -a | wc -w
Mike Kail:
o simply show how many files there, use
% find . -type f -print | wc -l
Others where similar to Dave McFerren's
Continuing Thanks
Mike Kail
Gary Lee
Other who have sent but not received
THANK YOU!!
Rick Dempster
>
> I have a user who wants a DOS dir type of return under Unix. Basically, he
> needs to know how many files are in a subdirectory. I've looked in man ls,
du,
> quot and df which did not show an option for giving the number of files.
>
> I thought I saw this question asked a couple of years ago, but could not dig
the
> answer out of the archives.
>
> If there is a quick method could someone please let me know, else I will write
a
> quick script to do it. I don't want to re-invent the wheel.
>
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:01 CDT