Simple file count question

Uwe Doering gemini at geminix.org
Mon Mar 15 23:37:30 PST 2004


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
gemini at geminix.org  |  http://www.escapebox.net


More information about the freebsd-questions mailing list