[Ma-linux] Re: [Novalug] How to get the number of files in a given directory
Mike Shade
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.
>
>
Janina,
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
-- Mike
> 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.
>
> Janina
>
>
>> Enjoy
>> -g-
>>
>> 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?
>>>
>>> TIA,
>>>
>>> Jay Hart
>>>
>>> _______________________________________________
>>> Novalug mailing list
>>> Novalug at calypso.tux.org
>>> http://calypso.tux.org/cgi-bin/mailman/listinfo/novalug
>>>
>>>
>> _______________________________________________
>> Ma-linux mailing list
>> Ma-linux at calypso.tux.org
>> http://calypso.tux.org/cgi-bin/mailman/listinfo/ma-linux
>>
>
>
More information about the Ma-linux
mailing list