Linux: Find files without string

Finding files with a string is easy, but finding files without a string …

My problem was to find all files named “.ebuild” containing “epatch” but not containing “eutils” …

Solution 1, slow

find /usr/portage/ -name "*.ebuild" -exec grep -lR 'epatch' {} \; | xargs grep -L 'eutils'
same, but writing to a file:
find /usr/portage/ -name "*.ebuild" -exec grep -lR 'epatch' {} \; | xargs grep -L 'eutils' > ebuild_wo_epatch.list

It’slow, but it works. The solution below is superior.

Solution 2, way better

Then I found this one:
find /usr/portage/ -name \*.ebuild -print0 \
| xargs -0 grep -Zli 'epatch' \
| xargs -0 grep -Li 'eutils'

This seems easier to understand – but more important: This is faster, way faster then the above!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: