Re: Simple file count question
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:[EMAIL PROTECTED]) Daemon Dancing in the Dark, a FreeBSD weblog: http://freebsd.amazingdev.com/blog/ ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Simple file count question
* Dave Carrera <[EMAIL PROTECTED]> [2004-03-15 23:02]: > Hi List, > > 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 > > Dave C > I don't know if this is the most elegant way, but ls | grep ^db | wc -l will do it. -- Joshua I thought my people would grow tired of killing. But you were right, they see it is easier than trading. And it has its pleasures. I feel it myself. Like the hunt, but with richer rewards. -- Apella, "A Private Little War", stardate 4211.8 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Simple file count question
Craig Reyenga wrote: find /path/to/dir -type f -name db\* -print | wc -l would count the number of files that begin with 'db' in the name, under the '/path/to/dir' directory. man find and man wc for more action. Be careful in case that directory contains subdirectories, since 'find' will traverse them by default as well. If you want to count files only in the directory level of '/path/to/dir' you may want to add '-maxdepth 1', like so: find /path/to/dir -type f -name db\* -maxdepth 1 -print | wc -l Uwe -- Uwe Doering | EscapeBox - Managed On-Demand UNIX Servers [EMAIL PROTECTED] | http://www.escapebox.net ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Simple file count question
find /path/to/dir -type f -name db\* -print | wc -l would count the number of files that begin with 'db' in the name, under the '/path/to/dir' directory. man find and man wc for more action. -Craig - Original Message - From: "Dave Carrera" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, March 16, 2004 2:01 AM Subject: Simple file count question Hi List, 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 Dave C --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.622 / Virus Database: 400 - Release Date: 13/03/2004 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"