From owner-freebsd-questions@FreeBSD.ORG Tue Mar 16 07:42:13 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 46B0216A4CE for ; Tue, 16 Mar 2004 07:42:13 -0800 (PST) Received: from mail5.speakeasy.net (mail5.speakeasy.net [216.254.0.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id DE7E843D1D for ; Tue, 16 Mar 2004 07:42:08 -0800 (PST) (envelope-from jdarnold@buddydog.org) Received: (qmail 13125 invoked from network); 16 Mar 2004 15:42:06 -0000 Received: from dsl092-076-225.bos1.dsl.speakeasy.net (HELO buddydog.org) ([66.92.76.225]) (envelope-sender ) by mail5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 16 Mar 2004 15:42:06 -0000 Message-ID: <4057206B.5050805@buddydog.org> Date: Tue, 16 Mar 2004 10:42:35 -0500 From: Jonathan Arnold User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7b) Gecko/20040310 MultiZilla/1.6.0.0e X-Accept-Language: en-us, en, ja MIME-Version: 1.0 To: freebsd-questions@FreeBSD.ORG References: <002501c40b24$8c600e10$0301a8c0@daveslaptop> In-Reply-To: <002501c40b24$8c600e10$0301a8c0@daveslaptop> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: Simple file count question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Mar 2004 15:42:13 -0000 Dave Carrera wrote: > I know this is going to be simple but I cant find a suitable answer by > trawling the web so I ask how do I count the number of certain files in a > directory? > > So I am in my dir and want to count how many files begin with db and show me > the number. > > I hope you can help me and thank you in advance for any help you may give As you can see, the key command is 'wc'. It's a nice, simple little command that does one thing and one thing well - it counts "words". If you don't give it any flags, it tells you the number of lines, words, and bytes. Using -l will count the number of lines. So you pipe the output of a command to it and it will count stuff for you. Thus: $ ls db* |wc -l will give you a single number telling you the number of lines in its input; in this case, the input is the output of 'ls db*', which is a simple listing of all the files in the current directory beginning with 'db'. Thus, you get a count of the number of files in the directory that begin with db. A very typical Un*x way of doing things - string together building block commands to get your output. Flexbile if arcane. -- Jonathan Arnold (mailto:jdarnold@buddydog.org) Daemon Dancing in the Dark, a FreeBSD weblog: http://freebsd.amazingdev.com/blog/