Question: I want to **find** some files, in a non GNU environment

* in the current directory only
* with extension **\*.ext1** and **\*.ext2**,
* but not **name1.\*** or **name2.\***

The following command works, but may be not efficient, because the shell expands `./*` and **find** can get a huge list of files and directories.

```
find ./* -prune \( -name '*ext1' -o -name '*ext2' \) -a ! \( -name 'name1*' -o -name 'name2*' \)

```

**Update:**

I'm working on AIX, there is no **-maxdepth** option.

Answer: 
In your current directory you can use `ls` with `grep` (assuming your file names don't contain newline characters):

```
ls -a | grep -E '\.ext(1|2)$' | grep -vE '^name(1|2)\.'

```
Since you have bash available, you can use its [extended pattern matching](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html#Pattern-Matching):

```
shopt -s extglob
files=( !(name1|name2).@(ext1|ext2) )

```

This says: all the files in the current directory that do *not* start with "name1" or "name2", followed by a period, followed by *either* "ext1" or "ext2".

For a sample run:

```
$ touch name1.ext1 name1.ext2 name2.ext1 name2.ext2 name3.ext1 name3.ext2 name3.ext3
$ files=( !(name1|name2).@(ext1|ext2) )
$ declare -p files
declare -a files='([0]="name3.ext1" [1]="name3.ext2")'

```

Note that if you have a simple filename like "name3.ext2", you have to choose where to put the period for the pattern matching -- either in "name3." *or* in ".ext2"; if you have longer filenames, such as "name3.intermediate.ext2", then you could use dots and a glob in the middle:

```
$ files=( !(name1|name2).*.@(ext1|ext2) )

```