I have a question concerning linux commands. How do I count all the files that begin with letters from a to g?
The GNU implementation of the
ls command (which you are using since you are running Linux) will find all files in the current directory starting with a character a-g.
It tells to ignore all files that do not start with a character in the range
! inverts the filter.
Next run the output through
wc -l to count the lines.
The full command will thus be:
ls --ignore='[!a-g]*' | wc -l
This solution will not recurs into subdirectories.
GNU find can do that for you:
find ./ -type f -maxdepth 1 -iname "[a-g]*" 2> /dev/null | wc -l
this finds all files (not directories) under
./ but digs into no further directories and matches the name (case insensitive) of the file beginning with "a-g", redirects all errors to
/dev/null and then counts the files