How to find files that contain a string in its content OR the path?

Posted on

Problem :

Find and grep does not work afaik because I need to create a list of files that satisfy EITHER requirement, not both. I assume this requires more than a one-liner. Any suggestions?

Solution :

It is possible with the following command:

comm  -3 <(find path -name '*string*' | sort) 
         <( grep -r 'string' path | sed s=^=./= | sort) 

You might need to change the sed part to make the paths reported by find and grep compatible. The -3 switch to comm suppresses printing the files that appear in both the lists.

Leave a Reply

Your email address will not be published. Required fields are marked *