Tomasz Rakowski
Tomasz Rakowski

Reputation: 1062

Find specific string in subdirectories and order top directories by modification date

I have a directory structure containing some files. I'm trying to find the names of top directories that do contain a file with specific string in it.

I've got this:

grep -r abcdefg . | grep commit_id | sed -r 's/\.\/(.+)\/.*/\1/';

Which returns something like:

topDir1
topDir2
topDir3

I would like to be able to take this output and somehow feed it into this command:

ls -t | grep -e topDir1 -e topDir2 -e topDir3

which would returned the output filtered by the first command and ordered by modification date.

I'm hoping for a one liner. Or maybe there is a better way of doing it?

Upvotes: 1

Views: 113

Answers (1)

Barmar
Barmar

Reputation: 782166

This should work as long as none of the directory names contain whitespace or wildcard characters:

ls -td $(grep -r abcdefg . | grep commit_id | dirname)

Upvotes: 1

Related Questions