[Ma-linux] How to get the number of files in a given directory

DonJr djr1952 at hotpop.com
Thu Jan 10 09:29:16 EST 2008


check out the effect of the ls option: --almost-all

IE from 'ls --help'
       -A, --almost-all  do not list implied . and ..


<GRIN>
  

On Thu, 2008-01-10 at 02:20 -0500, Joseph S D Yao wrote:
> For 'ls' in both examples please read 'ls -a', I must be getting tired!
> 
> On Thu, Jan 10, 2008 at 02:11:55AM -0500, Joseph S D Yao wrote:
> > On Wed, Jan 09, 2008 at 07:51:59PM -0500, Jay Hart wrote:
> > > How can you get the number of files in a directory?
> > > 
> > > for example, say /usr/local/bin had ten files (not including . and ..)
> > > 
> > > What command(s) would I issue to get a return for the number of files, in this
> > > case 10, back at the command line?
> > 
> > 
> > Distinguo.
> > 
> > Number of ENTRIES, less "." and "..":
> > 
> > if [ ! -d "${DIR}" ]; then echo "${DIR}: not a dir" >&2; exit 1; fi
> > ls "${DIR}" | grep -v '^\.$' | grep -v '^\.\.$' | wc -l
> > 
> > Number of PLAIN FILES, not including directories, block special files,
> > character special files, symbolic links, named pipes, fifos, etc., etc.:
> > 
> > if [ ! -d "${DIR}" ]; then echo "${DIR}: not a dir" >&2; exit 1; fi
> > ls -l "${DIR}" | grep '^-' | wc -l
> 
> 




More information about the Ma-linux mailing list