Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 03 Nov 2007 13:48:26 +0100
From:      Pietro Cerutti <gahr@gahr.ch>
To:        White Hat <pigskin_referee@yahoo.com>
Cc:        FreeBSD Users Questions <freebsd-questions@freebsd.org>
Subject:   Re: Determining the number of files in a directory
Message-ID:  <472C6E1A.1000408@gahr.ch>
In-Reply-To: <538619.51984.qm@web34408.mail.mud.yahoo.com>
References:  <538619.51984.qm@web34408.mail.mud.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigE30C60653667F944FC260FA9
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

White Hat wrote:
> This is probably a dumb question; however, I never let a little thing l=
ike that bother me in the past.
> =20
> 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.
> =20
> Other than, by writing a script to accomplish this feat, how could I ac=
hieve 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.



> =20
> Thanks!
> =20


--=20
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp


--------------enigE30C60653667F944FC260FA9
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFHLG4fwMJqmJVx944RCniTAKCkETa/Ax5Bit6+bsSJbzmO/Mn+FQCgikT9
lqpLqasD8D+DUJM0IEdvUtw=
=ZviT
-----END PGP SIGNATURE-----

--------------enigE30C60653667F944FC260FA9--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?472C6E1A.1000408>