0

This question already has an answer here:

$ ls -l JSON_files/*.json | wc -l
bash: /usr/bin/ls: Argument list too long
0

How can I get the count of files in a folder if I have 300k or 1M or more JSON files in a directory?

marked as duplicate by muru bash Oct 18 '18 at 4:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

The simplest way is avoid the command line wild card expansion, then filter for the names you want from the (non-commandline) output:

ls -l JSON_files/ | fgrep .json | wc
1
ls -f *.json | wc -l

"By default ls sorts the names, which can take a while if there are a lot of them. Also there will be no output until all of the names are read and sorted. Use the ls -f option to turn off sorting."

Original command :

ls -f | wc -l

answered Sep 15 '09 at 13:55, mark4o

Source : Fast Linux File Count for a large number of files https://stackoverflow.com/questions/1427032/fast-linux-file-count-for-a-large-number-of-files

find . -name "*.json" | wc -l

Not the answer you're looking for? Browse other questions tagged or ask your own question.