Find every directory named XYZ under the DVLP directory

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find every directory named XYZ under the DVLP directory
# 1  
Old 10-16-2013
Find every directory named XYZ under the DVLP directory

I only want to find files under each branch of the directory tree inside directories named XYZ and there are multiple XYZ directories?
# 2  
Old 10-16-2013
find DVLP -type d -name "XYZ"

EDIT: Actually, do you want the directories, or the files in the directories? Your post title & post content say different things...
# 3  
Old 10-16-2013
I want the file names please?

---------- Post updated at 01:18 PM ---------- Previous update was at 01:17 PM ----------

Sorry about that!

---------- Post updated at 01:20 PM ---------- Previous update was at 01:18 PM ----------

would it be ?
find DVLP -type f -name "XYZ"

# 4  
Old 10-16-2013
find DVLP -type d -name XYZ -print0 | xargs -0 -I{} find {} -maxdepth 1 -type f

find DVLP -type f -name "XYZ"
would get you files named XYZ. I think what you want is the files named anything which are inside directories XYZ?
# 5  
Old 10-16-2013
Yes correct! Thanks!

---------- Post updated at 01:24 PM ---------- Previous update was at 01:23 PM ----------

Which code is correct? What does that xargs part do?

---------- Post updated at 01:25 PM ---------- Previous update was at 01:24 PM ----------

So to find all of the xml files under there it would be?
find DVLP -type f -name "XYZ/*.xml"

# 6  
Old 10-16-2013
find DVLP -type d -name XYZ -print0 finds directories under DVLP which are called XYZ. -print0 outputs them NUL-terminated, which is just a precaution in case any directory names have whitespace in them.

find <path> -maxdepth 1 -type f finds files directly under <path> (i.e. it doesn't check subdirectories of <path>)

xargs passes its input as arguments to the command specified. By default it separates its input using whitespace, but -0 overrides that to use NUL. Also by default, the arguments are supplied as the last parameter to the command, but by using -I<replace string> it will pass them wherever <replace string> is in the command.

In this case, I'm using -I{}, so xargs passes its input (the list from the directory find) to the files find as the path to start from.

Originally Posted by emc^24sho
So to find all of the xml files under there it would be?
find DVLP -type f -name "XYZ/*.xml"

No - that would find files which actually contain / in the filename itself (which is highly unlikely for Unix).

If you wanted all xml files under DVLP you could do:
find DVLP -type f -name "*.xml"

If you only want xml files which are in directories called XYZ which are under DVLP then you could do:
find DVLP -type d -name XYZ -print0 | xargs -0 -I{} find {} -maxdepth 1 -type f -name "*.xml"

This User Gave Thanks to CarloM For This Post:
# 7  
Old 10-16-2013
I want to find every xml file in XYZ directories under DVLP.

---------- Post updated at 01:47 PM ---------- Previous update was at 01:42 PM ----------

Then I could use another
 | xargs to grep -l "Status"

to get all of the xml files of that contain "Status"?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find and get a file in an entire directory with an excluded directory specified?

How to get a file 'zlib.h' in an entire directory with an excluded directory specified lives under that starting directory by using find command, as it failed on: $ find . -name 'zlib.h' -a -ipath 'CHROME.TMP' -prune -o -print it'll just list entirely up (2 Replies)
Discussion started by: abdulbadii
2 Replies

2. Shell Programming and Scripting

perl Compare zone files in directory with what is listed in named.conf

I would really appreciate any assistance that I can get here. I am fairly new to perl. I am trying to rewrite my shell scripts to perl. Currently I have a shell script (using sed, awk, grep, etc) that gets a list of all of the zone files in a directory and then looks in named.conf for what... (0 Replies)
Discussion started by: brianjb
0 Replies

3. UNIX for Dummies Questions & Answers

Accessing a badly named directory

Someone in my group manages to name a directory -p. I'm not sure how they did it but it's there. How can I access the directory or change it's name? I've tried to quote it (cd "-p"). I've tried to use the backslash (cd \-p) and a combination of the two (cd "\-p" and cd \-p). each of these... (3 Replies)
Discussion started by: scottwevans
3 Replies

4. Shell Programming and Scripting

Move all files not in a directory into a subdirectory named for each given file

Hi Everyone! Looking for some help with a script that will take all files in any given root folder (which are not already in a folder) and put them into separate folders with the name of each given file. Any ideas? Thank you! (1 Reply)
Discussion started by: DanTheMan
1 Replies

5. Homework & Coursework Questions

C Program to search and read all named pipes in current directory

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a C program to search the current directory for all pipes. 1. It will print the pipe... (2 Replies)
Discussion started by: natwickley
2 Replies

6. Shell Programming and Scripting

Need to find recursively all shell script in the /xyz directory

Pls. advise how to find or used grep recursively all shell script files. Some files doesnt have a .sh or .ksh extension name. find / -name "*" |xargs grep bin |grep sh ?? TIA (1 Reply)
Discussion started by: budz26
1 Replies

7. Shell Programming and Scripting

Create a directory named as the current date

I am preparing a shell script to backup a few config files on a daily basis, with a retention of 30 days. Need some help with syntax/examples: The shell script (running as cron) would require the following: 1. create a sub-directory within a specified (backup) directory, in the format... (3 Replies)
Discussion started by: FeNiCrC_Neil
3 Replies

8. UNIX for Dummies Questions & Answers

Script to find a string in a directory/sub-directory

I'm trying to find this string 'preparing string IBE_Quote_W1_Pvt.SaveWrapper for quote_header_id’ in my Apache log file directory. The log file that contains this string may be in a parent direcotry or a sub-directory. I have tried 'grep' and 'awk' with no success. I would like to get the path... (3 Replies)
Discussion started by: gross
3 Replies

9. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

10. UNIX for Dummies Questions & Answers

create directory named current date

Since this site solved my problems before, I am back for more (solutions) I down load via a script every day a file that has the same name as the file of the day before. I want to move that file to its own directory like: /archive/jul30 How do I capture the systems date in a script an... (2 Replies)
Discussion started by: flowrats
2 Replies
Login or Register to Ask a Question