I only want to find files under each branch of the directory tree inside directories named XYZ and there are multiple XYZ directories?
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...
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"
Try:
find DVLP -type d -name XYZ -print0 | xargs -0 -I{} find {} -maxdepth 1 -type f
EDIT:
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?
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"
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>)
man xargs (linux) 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.
EDIT:
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"
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"?
You could:
find DVLP -type d -name XYZ -print0 | xargs -0 -IREPL find REPL -maxdepth 1 -type f -name "*.file" | xargs grep -l Status
You could also just run it directly from the second find command:
find DVLP -type d -name XYZ -print0 | xargs -0 -IREPL find REPL -maxdepth 1 -type f -name "*.xml" -exec grep -l Status {} \;
EDIT: I changed the xargs string to something else as otherwise it's confused with find's exec string.