Your error message argument list too long comes from the ***** of ls *.txt.
This limit is a safety for both binary programs and your Kernel. See ARG_MAX, maximum length of arguments for a new process for more information about it, and how it's used and computed.
There is no such limit on pipe size. So you can simply issue this command:
find -type f -name '*.txt' | wc -l
NB: On modern Linux, weird characters in filenames (like newlines) will be escaped with tools like ls or find, but still displayed from *****. If you are on an old Unix, you'll need this command
find -type f -name '*.txt' -exec echo \; | wc -l find files from all subdirectories:find . > tmp1.listAnswer from:
https://unix.stackexchange.com/questions/38955/argument-list-too-long-for-ls