[NTLUG:Discuss] Simple bash shell question
Robert Citek
robert.citek at gmail.com
Fri Mar 30 16:54:19 CDT 2007
Patrick R. Michaud wrote:
> On Fri, Mar 30, 2007 at 04:04:19PM -0500, Robert Citek wrote:
>> If all you want to do is count the number of files:
>>
>> fcount=$(ls *.mpg | wc -l)
>>
>> Just be aware that for large number of *.mpg files you'll exceed bash's
>> expansion buffer.
>
> To avoid exceeding bash's buffer:
>
> fcount=$(find . -name '*.mpg' | wc -l)
Just be aware that 'find ...' will descend through the file hierarchy.
Here's another approach using 'ls':
fcount=$(ls | grep -c mpg$)
Add "-i" to grep to make it case insensitive and catch files like
foo.MPG, foo.mpG, foo.MpG, etc.
Regards,
- Robert
More information about the Discuss
mailing list