Quamrul Islam Quamrul Islam -4 years ago 158
Linux Question

Command to check for a very large number of .gz files in a directory

Below is the current days file. Previous days file converted to .gz by system. I wanted to find the total count of last days specific .gz files. I tried the below command which gives me the error. Please suggest

bash-3.2$ ls -lrth|tail

299K Mar 23 2017 N08170323091903766
333K Mar 23 2017 N08170323091903771
328K Mar 23 2017 N09170323091903776
367K Mar 23 2017 N09170323091903782
347K Mar 23 2017 N04170323092003784
368K Mar 23 2017 N08170323092003783

***bash-3.2$ ls -lrth N08170322*|wc -l***

bash: /usr/bin/ls: Arg list too long


***bash-3.2$ zcat N08170322*.gz|wc -l***

bash: /usr/bin/zcat: Arg list too long


Answer Source

This is happening because you have too many files in the directory.

You can easily get around the first issue:

ls | grep -c N08170322

or, to be even more precise:

ls | grep -c '^N08170322'

would give you the list of files.

If you really want to count the lines of all the zipped files in one shot, you can do this:

find . -name "N08170322*" -exec zcat {} + | wc -l

See also:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download