From owner-freebsd-questions@FreeBSD.ORG Sat Nov 3 19:53:36 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7BEED16A421 for ; Sat, 3 Nov 2007 19:53:36 +0000 (UTC) (envelope-from erik@cederstrand.dk) Received: from mail.itu.dk (pluto.itu.dk [130.226.142.18]) by mx1.freebsd.org (Postfix) with ESMTP id 34C2313C4DD for ; Sat, 3 Nov 2007 19:53:36 +0000 (UTC) (envelope-from erik@cederstrand.dk) Received: from localhost (unknown [10.0.0.3]) by mail.itu.dk (Postfix) with ESMTP id 5134836F2BA for ; Sat, 3 Nov 2007 14:36:19 +0100 (CET) X-Virus-Scanned: amavisd-new at itu.dk Received: from superman.itu.dk ([130.226.142.5]) by localhost (daredevil.itu.dk [130.226.142.26]) (amavisd-new, port 10024) with ESMTP id uNCW7RR2V6hS for ; Sat, 3 Nov 2007 14:36:15 +0100 (CET) Received: from wimac.littlebit.dk (unknown [85.233.238.191]) by superman.itu.dk (Postfix) with ESMTP id D7B1D9E657 for ; Sat, 3 Nov 2007 14:35:40 +0100 (CET) Message-ID: <472C7905.5020307@cederstrand.dk> Date: Sat, 03 Nov 2007 14:35:01 +0100 From: Erik Cederstrand User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: FreeBSD Users Questions References: <538619.51984.qm@web34408.mail.mud.yahoo.com> <20071103124151.GA3207@torus.slightlystrange.org> <20071103124932.GB3207@torus.slightlystrange.org> In-Reply-To: <20071103124932.GB3207@torus.slightlystrange.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: Determining the number of files in a directory X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Nov 2007 19:53:36 -0000 Daniel Bye wrote: > On Sat, Nov 03, 2007 at 12:41:51PM +0000, Daniel Bye wrote: >>> [...] >>> 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 > > Except of course, that would descend into the subdirectories you're trying > not to count... Sorry - an object lesson in not hitting send before you've > tested what you scribbled. ls -aF | grep -v /$ | wc -l is a quick, if somewhat ugly, way to do it. It counts the dotfiles too. Erik