Determining the number of files in a directory

Daniel Bye freebsd-questions at slightlystrange.org
Sat Nov 3 05:42:28 PDT 2007


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

Dan

-- 
Daniel Bye
                                                                     _
                                              ASCII ribbon campaign ( )
                                         - against HTML, vCards and  X
                                - proprietary attachments in e-mail / \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20071103/b998100e/attachment.pgp


More information about the freebsd-questions mailing list