Unable to find files using wildcard on AIX.

I wish to seach for files extensions .xml, .jsp followed by <whatever> charecters under directory custom while excluding folders "BACKUP" & "TMP"

Thus for a sample set like below:

/tmp/custom/moht.xml_tmp
/tmp/custom/raw/testxmlfile
/tmp/custom/raw/test.jsp
/tmp/custom/test.xml
/tmp/custom/BACKUP/test.xml.bkp
/tmp/custom/log/test.xml.bkp

Use the below command to create the sample test files on your server for testing purpose:

mkdir -p /tmp/custom/BACKUP; mkdir -p /tmp/custom/log; mkdir -p /tmp/custom/raw; touch /tmp/custom/moht.xml_tmp; touch /tmp/custom/raw/testxmlfile; touch /tmp/custom/test.xml; touch /tmp/custom/BACKUP/test.xml.bkp; touch /tmp/custom/log/test.xml.bkp; touch /tmp/custom/raw/test.jsp

My find should yeild only these two files as output:

/tmp/custom/moht.xml_tmp
/tmp/custom/log/test.xml.bkp

I tried the below command but it does not give me the desired output.

/opt/freeware/bin/find /tmp/custom -type f \( -name '*.xml*' -o -name '*.js*' -o -name '*.jsp*' \) | grep -v '/BACKUP/' | grep -v '/REJECTED/'

Current Output:

/tmp/custom/log/test.xml.bkp
/tmp/custom/moht.xml_tmp
/tmp/custom/test.xml

It yeilds files having extension exactly matching .xml .js and .jsp i.e /tmp/custom/test.xml which it should not.

I'm on AiX 6.1

Can you please suggest ?

Please post the output you are getting.

You post your sample input, your code, but you do not post your output (correct or not, error messages.... your output).

INPUT ---> YOUR CODE ---> OUTPUT

Please. It is not that hard to be complete when posting a question, this I promise you :slight_smile: But it makes is easier for people in the community when you post this information.

Thanks.

You should find files with at least one more char after the extension, then:

find /tmp/custom -type f \( -name '*.xml?*' -o -name '*.js?*' -o -name '*.jsp?*' \) | grep -v '/BACKUP/'
/tmp/custom/moht.xml_tmp
 /tmp/custom/log/test.xml.bkp

man bash :

find uses shell metacharacters (`*', `?' or `[]' for example) ( man find )

@Neo Hi, Thank you for your inputs. I have updated the Original Post with the output.

(@Neo, nothing was really missing. I was able to construct the output from the given input sample and the given code. And no error message.)

The * in shell glob and find glob means every - even zero - amount of characters, so have another ? that means one character.
Further, you can egrep -v '/BACKUP/|/REJECTED/' the unwanted files, but most efficient is to let find prune=skip these directories.
As a rule of thumb, have the pruned directories first and continue with -o =OR=OTHERWISE.

find /tmp/custom -type d \( -name "BACKUP" -o -name "REJECTED" \) -prune -o -type f \( -name '*.xml?*' -o -name "*.js?*" \) -print

You must explicitly print on the desired branch in order to not implicitly print on both branches.
Llast but not least, *.js?* covers *.jsp?* so the letter is not needed. (Perhaps you want -name "*.js?*" \! -name "*.jsp" or -name "*.js??*" ?)

This is not an issue of "being able to construct the output" Anyone can construct the output with basic skills.

The point is that readers should not have to construct the output. OPs should post their output.

These are the rules.

Thanks.

@MadeInGermany i tried the ?* but the problem is i get .jsp files in the output because of '*.js?*' when a .jsp should not be returned in the output when i have -o -name '*.js?*'

/opt/freeware/bin/find /tmp/custom -type f \( -name '*.xml?*' -o -name '*.js?*' -o -name '*.jsp?*' \) | grep -v '/BACKUP/' | grep -v '/REJECTED/'

Output:

/tmp/custom/raw/test.jsp
/tmp/custom/log/test.xml.bkp
/tmp/custom/moht.xml_tmp

As I suggested, have -name "*.js?*" \! -name "*.jsp" or cheat with -name "*.js??*" .
And most easy is of course -name "*.jsp?*" .

1 Like

If you (roughly) know what to exclude (here: .jsp), try

find /tmp/custom -type f \( -name '*.xml?*' -o -name '*.js[^p]*' -o -name '*.jsp?*' \) | grep -v '/BACKUP/'
/tmp/custom/moht.xml_tmp
/tmp/custom/log/test.xml.bkp

Attention, the standard shell and find glob has [!p] - [^p] is a GNU/libc extension.
(But the latter is standard in RegularExpression.)

Thank you @MadeInGermany that answers my query.