From owner-freebsd-questions@FreeBSD.ORG Sat Nov 3 14:45:01 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 0F48D16A417 for ; Sat, 3 Nov 2007 14:45:01 +0000 (UTC) (envelope-from lists@jnielsen.net) Received: from ns1.jnielsen.net (ns1.jnielsen.net [69.55.238.237]) by mx1.freebsd.org (Postfix) with ESMTP id E10C913C4AA for ; Sat, 3 Nov 2007 14:44:59 +0000 (UTC) (envelope-from lists@jnielsen.net) Received: from localhost (jn@ns1 [69.55.238.237]) (authenticated bits=0) by ns1.jnielsen.net (8.12.9p2/8.12.9) with ESMTP id lA3Eid69059228; Sat, 3 Nov 2007 10:44:40 -0400 (EDT) (envelope-from lists@jnielsen.net) From: John Nielsen To: freebsd-questions@freebsd.org, Daniel Bye Date: Sat, 3 Nov 2007 10:44:43 -0400 User-Agent: KMail/1.9.7 References: <538619.51984.qm@web34408.mail.mud.yahoo.com> <20071103124151.GA3207@torus.slightlystrange.org> <20071103124932.GB3207@torus.slightlystrange.org> In-Reply-To: <20071103124932.GB3207@torus.slightlystrange.org> X-Face: #X5#Y*q>F:]zT!DegL3z5Xo'^MN[$8k\[4^3rN~wm=s=Uw(sW}R?3b^*f1Wu*.<=?utf-8?q?of=5F4NrS=0A=09P*M/9CpxDo!D6?=)IY1w<9B1jB; tBQf[RU-R<,I)e"$q7N7 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200711031044.43523.lists@jnielsen.net> X-Virus-Scanned: ClamAV version 0.88.4, clamav-milter version 0.88.4 on ns1.jnielsen.net X-Virus-Status: Clean Cc: White Hat 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 14:45:01 -0000 On Saturday 03 November 2007, Daniel Bye wrote: > On Sat, Nov 03, 2007 at 12:41:51PM +0000, Daniel Bye wrote: > > On Sat, Nov 03, 2007 at 05:27:06AM -0700, White Hat wrote: > > > This is probably a dumb question; however, I never let a little thing > > > like that bother me in the past. > > > > Heheh! You and many more, my friend, myself absolutely included! > > > > > 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. > > > > $ ls | wc -l > > > > will show you how many files and directories in the current (target) > > directory. To count just files, and exclude directories, you could try > > something like > > > > $ find /target/directory -type f -print | wc -l > > Except of course, that would descend into the subdirectories you're > trying not to count... Sorry - an object lesson in not hitting send > before you've tested what you scribbled. find /target/directory -type f -maxdepth 1 | wc -l should do the trick. See also man find and man wc, of course. JN