From owner-freebsd-questions@FreeBSD.ORG Sat Nov 3 22:25:37 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 15DD116A419 for ; Sat, 3 Nov 2007 22:25:37 +0000 (UTC) (envelope-from gahr@gahr.ch) Received: from cpanel03.rubas-s03.net (cpanel03.rubas-s03.net [195.182.222.73]) by mx1.freebsd.org (Postfix) with ESMTP id C438913C4A5 for ; Sat, 3 Nov 2007 22:25:36 +0000 (UTC) (envelope-from gahr@gahr.ch) Received: from 80-218-191-236.dclient.hispeed.ch ([80.218.191.236] helo=gahrtop.localhost) by cpanel03.rubas-s03.net with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1IoIR2-0005Wa-Tz; Sat, 03 Nov 2007 13:49:08 +0100 Message-ID: <472C6E1A.1000408@gahr.ch> Date: Sat, 03 Nov 2007 13:48:26 +0100 From: Pietro Cerutti User-Agent: Thunderbird 2.0.0.6 (X11/20071101) MIME-Version: 1.0 To: White Hat References: <538619.51984.qm@web34408.mail.mud.yahoo.com> In-Reply-To: <538619.51984.qm@web34408.mail.mud.yahoo.com> X-Enigmail-Version: 0.95.5 OpenPGP: id=9571F78E; url=http://www.gahr.ch/pgp Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigE30C60653667F944FC260FA9" X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cpanel03.rubas-s03.net X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - gahr.ch X-Source: X-Source-Args: X-Source-Dir: Cc: FreeBSD Users Questions Subject: Re: Determining the number of files in a directory X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Nov 2007 22:25:37 -0000 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--