[Ma-linux] Re: [Novalug] How to get the number of files in a given directory
mshade at mshade.org
Thu Jan 10 21:14:34 EST 2008
Janina Sajka wrote:
> geoffm writes:
>> ls /usr/local/bin/ | wc -l
> No, that won't work. You're printing multiple filenames per line. You
> need the '-1' argument to ls in order to rely on wc counting the number
> of lines correctly.
Though when referenced directly ls tends to output multiple per row,
when piped it actually does list one per line. I dont' know the rhyme
or reason to this, or whether it's configuration or GNU version
dependent, but it does work that way.
To see it in action:
ls | less
> However, your version counting words would do it:
> ls /usr/local/bin/ |wc -w
> However, this one is a problem if it's at all possible that you'd have
> filenames with spaces, a la Windows.
>> Jay Hart wrote:
>>> How can you get the number of files in a directory?
>>> for example, say /usr/local/bin had ten files (not including . and ..)
>>> What command(s) would I issue to get a return for the number of files, in this
>>> case 10, back at the command line?
>>> Jay Hart
>>> Novalug mailing list
>>> Novalug at calypso.tux.org
>> Ma-linux mailing list
>> Ma-linux at calypso.tux.org
More information about the Ma-linux