Date: Tue, 16 Mar 2004 10:42:35 -0500 From: Jonathan Arnold <jdarnold@buddydog.org> To: freebsd-questions@FreeBSD.ORG Subject: Re: Simple file count question Message-ID: <4057206B.5050805@buddydog.org> In-Reply-To: <002501c40b24$8c600e10$0301a8c0@daveslaptop> References: <002501c40b24$8c600e10$0301a8c0@daveslaptop>
next in thread | previous in thread | raw e-mail | index | archive | help
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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4057206B.5050805>