White Hat wrote: > This is probably a dumb question; however, I never let a little thing like > that bother me in the past. > > Using FreeBSD-6.2 and Bash, how do I determine the number of files in a given > directory? I have tried all sorts of combinations using different flags with > the 'ls' command; however, none of them displays the number of files in the > directory. > > Other than, by writing a script to accomplish this feat, how could I achieve > my goal?
I find that the most intuitive way is to use something like: find . -maxdepth 1 | wc -l Where you can specify how many levels of subdirectories to include in the count. Please note that count also includes the current directory ("."). To exclude hidden files (.*), use find * -maxdepth 0 | wc -l or expr `ls -l | wc -l` - 1 instead. > > Thanks! > -- Pietro Cerutti PGP Public Key: http://gahr.ch/pgp
Description: OpenPGP digital signature