ksh: /bin/grep: arg list too long

when i run the command below in a directory which contains too
many files i got the error: ksh: /bin/grep: arg list too long

ls|grep AA*B*

how can i handle this problem?

How many files do you have in that directory? The error is that grep is unable to handle the list of files sent in as there are too many of them.

i have approximately 10000 files in the directory

hi blowtorch,

Iam also getting the same problem,can u tell us the limit of ls command.
till how many file will it work.

I did a search on this forum and came up with the following:

What do you want to do ?

To find files matching the pattern AA*B* (ie. AA123B456) in current directory :

ls | grep '^AA.*B'

To find files matching regular expression AA*B* (ie (AAAAB) in current directory :

ls | grep 'AA*B*'

In all cases you must protect the pattern or regular expression with suotes to prevent an interpretation by the shell.

Jean-Pierre.