1
$ 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?

Mona Jalal
  • 4,545
  • 21
  • 68
  • 99

2 Answers2

2

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
ubfan1
  • 17,838
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
Gounou
  • 576