I am new to linux. I have a directory in linux with approx 250,000 files I need to find count of number of files matching a pattern.
I tried using following command :
You should generally avoid ls in scripts and in fact, performing the calculation in a shell function will avoid the "argument list too long" error because there is no exec
boundary and so the ARGV_MAX
limit doesn't come into play.
number_of_files () {
if [ -e "$1" ]; then
echo "$#"
else
echo 0
fi
}
The conditional guards against the glob not being expanded at all (which is the default out of the box; in Bash, you can shopt -s nullglob
to make wildcards which don't match any files get expanded into the empty string).
Try it:
number_of_files 20061101-20131101_kh5x7tte9n_2010_*