user2494770
user2494770

Reputation:

How to list the contents of a subdirectory after finding the directory

This is a rather specific question, but essentially what I was wondering is if there is anyway to list the contents of a directory below the one that I search for.

My case is that I have a parent directory with a ton of subdirectories that I want to search on to see if they contain a directory of a certain string. Since it's so big I make sure to limit my depth to two to avoid unnecessary searching. The first command is something like this:

find . -maxdepth 2 -type d -name "MWACluster15"

This will typically return something on the order of 30 matches. What I'd like to do then is list the contents of one of its subdirectories called logs. I thought maybe doing something like

find . -maxdepth 2 -type d -name "MWACluster15" | xargs ls logs/

might do the trick but it just returns the immediate contents of the directory. What I want is to list the contents of MWACluster15/logs/

Anyone know if this is possible without having to write a bash script?

Upvotes: 0

Views: 162

Answers (1)

Tom Fenech
Tom Fenech

Reputation: 74595

I guess you could use something like this:

find . -maxdepth 2 -type d -name "MWACluster15" -execdir ls {}/logs/ \;

-execdir executes a command from the directory in which the directory you're interested in is found. The {} is a placeholder which is substituted with the directory name "MWACluster15".

Upvotes: 3

Related Questions