Find: filename in every subdirectory matching a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find: filename in every subdirectory matching a pattern
# 1  
Old 03-06-2015
Find: filename in every subdirectory matching a pattern

Hi,

I have multiple directories built in following manner

Code:
/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
Code:
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
# 2  
Old 03-06-2015
How about:
Code:
find /app/*/upd ....

# 3  
Old 03-06-2015
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
Code:
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*''.


Last edited by wahi80; 03-06-2015 at 02:21 PM..
# 4  
Old 03-06-2015
That just warns there should no slashes used with -name, because file names never contains slashes..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 03-06-2015
Just to be perfectly clear, the command Scrutinizer was suggesting was:
Code:
find /app/*/upd -type f -name "*ONE*"

The warning message you got from find would be more likely from a command like:
Code:
find /app/blue/upd -type f -name '*app/blue/tmp*'

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find pattern suffix matching pattern

Hi, I am trying to get a result out of this but fails please help. Have two files /tmp/1 & /tmp/hosts. /tmp/1 IP=123.456.789.01 WAS_HOSTNAME=abcdefgh.was.tb.dsdc /tmp/hosts 123.456.789.01 I want this result in /tmp/hosts if hostname is already there dont want duplicate entry. ... (5 Replies)
Discussion started by: rajeshwebspere
5 Replies

2. UNIX for Dummies Questions & Answers

find Search - Find files not matching a pattern

Hello all, this is my first and probably not my last question around here. I do hope you can help or at least point me in the right direction. My question is as follows, I need to find files and possible folders which are not owner = AAA group = BBB with a said location and all sub folders ... (7 Replies)
Discussion started by: kilobyter
7 Replies

3. UNIX for Dummies Questions & Answers

FIND matching pattern of lines in a file

I need to search for two patterns in a file and find number of matching lines. find . -type f | xargs grep "DROP TABLE" | wc -l find . -type f | xargs grep "DROP SYNONYM" | wc -l The above code works. However I am looking at finding a commnd that will simplify as on a singe command... (2 Replies)
Discussion started by: Siva SQL
2 Replies

4. UNIX for Dummies Questions & Answers

Help with filename pattern matching

Hi, I have files in a directory with filenames that match three specific patterns: 1) *'.L2_LAC'* 2) *'.L2_LAC_OC'* 3) *'.L2_LAC_SST'* I would like to have an "ls" command that will list only files matching the first two patterns. However, if I type: ls *'.L2_LAC'* I will get files that... (2 Replies)
Discussion started by: msb65
2 Replies

5. UNIX for Dummies Questions & Answers

Pattern matching and Printing Filename

Hi, My requirement is to search for a paritcular string from a group of .gz files and to print the lines containing that string and the name of the files in which that string is present. Daily 500 odd .gz files will be generated in a directory(directory name will be in the form of... (4 Replies)
Discussion started by: krao
4 Replies

6. UNIX for Dummies Questions & Answers

find files NOT matching name pattern

Hi, I have following files in my directory: /TESTDONTDEL> ls -alt total 14 drwxr-xr-x 2 oracle dba 1024 May 15 06:30 . -rw-r--r-- 1 oracle dba 40 May 15 06:30 exception.txt -rw-r--r-- 1 oracle dba 19 May 15 06:22 ful_1234_test1.txt -rw-r--r-- 1... (2 Replies)
Discussion started by: sagarparadkar
2 Replies

7. UNIX for Dummies Questions & Answers

Find files matching a pattern

Hi, I am writing a BASH shell script. I would like to count all the files in the CURRENT directory matching a specific pattern. Could someone suggest the best/simplest way to do this. I have thought of these solutions (for simplicity the pattern is all files starting with A): ls -1 *A | wc -l... (5 Replies)
Discussion started by: msb65
5 Replies

8. Shell Programming and Scripting

Filename and Pattern matching

Hiiiii every one, I am facing a problem while giving a file name which has space in it. The problem is ... I have to read a file where the set of input files are stored. Now getting that name I have to open the file and i have to extract the name of the user from where it is written like"by... (2 Replies)
Discussion started by: kheyali Mitra
2 Replies

9. Shell Programming and Scripting

find and replace in subdirectory (filename & content - both)

Hi, I have to rename all occurance of CUST_MST to RESELLER_MST both in filename and file content under a directory (say D0) which contains multiple (2-3 levels) sub directory. Example: D0 -> D1 -> D2 has a file CUST_MST_TEMP.txt this contains : > cat /D0/D1/D2/CUST_MST_TEMP.txt... (3 Replies)
Discussion started by: sabyasm
3 Replies

10. Shell Programming and Scripting

Script to find file name for non matching pattern

Hi, I want to list only the file names which do not contain a specific keyword or search string. OS: Solaris Also is there any way ; through the same script I can save the output of search to a CSV (comma seperated) so that the file can be used for inventory purpose. Any assistance will... (5 Replies)
Discussion started by: sujoy101
5 Replies
Login or Register to Ask a Question