Find: filename in every subdirectory matching a pattern

Hi,

I have multiple directories built in following manner

/app/red/tmp
/app/blue/upd
/app/blue/tmp
/app/green/tmp
/app/red/upd
/app/green/upd

I have filenames having pattern ONE.XXX.dat TWO.ZZZ.dat and so on across the folders listed above

My objective is to list all filenames of a particular pattern in all upd sub-directories.

Currently I do it by writing individual commands like

find /app/blue/upd -type f -name "*ONE*"
find /app/red/upd -type f -name "*ONE*"
find /app/green/upd -type f -name "*ONE*"

Is there a way to combine above lines into one line?

Thanks

How about:

find /app/*/upd ....

Hi,

I forgot to mention that I'm using this command in a shell script. The * works fine at command prompt, but within script I get this error

find: warning: Unix filenames usually don't contain slashes (though pathnames do).  That means that '-name `*/app/blue/tmp*'' will probably evaluate to false all the time on this system.  You might find the '-wholename' test more useful, or perhaps '-samefile'.  Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ `*/app/blue/tmp*''.

That just warns there should no slashes used with -name, because file names never contains slashes..

1 Like

Just to be perfectly clear, the command Scrutinizer was suggesting was:

find /app/*/upd -type f -name "*ONE*"

The warning message you got from find would be more likely from a command like:

find /app/blue/upd -type f -name '*app/blue/tmp*'
1 Like