There is no limit (other than available memory) to the number of files that may be expanded by a bash
glob.
However when those files are passed as arguments to a command that is executed (as opposed to a shell builtin or function), then you may run into a limit of the execve()
system call on some systems. On most systems, that system call has a limit on the cumulative size of the arguments and environment passed to it, and on Linux also a separate limit on the size of a single arguments.
For more details, see:
To work around that limit, you can use (assuming GNU xargs
or compatible):
printf '%s\0' foo* | xargs -r0 rm -f
Above, since printf
is built-in (in bash
and most Bourne-like shells), we don't hit the execve()
limit. And xargs
will split the list of arguments into as many rm
invocations as needed to avoid the execve()
limitation.
With zsh
:
autoload zargs
zargs foo* -- rm -f
With ksh93
:
command -x rm -f foo*