i have active directory which contain multiple subdirectories.i want to find the list of files which should contains the string patterns as "String1" and "String2" respectively

  • I'd use ag for that. – Arkadiusz Drabczyk Aug 26 '19 at 10:51
  • 1
    Could you give more details and an example? – harrymc Aug 26 '19 at 10:53
  • i have different files like t1.js and t2.js and t3.js.only the file t3.js has two string patterns as "hello" and "world".i want to find the list of file should contain both the strings.which means my output become t3.js while using grep and find unix comands it results where ever the stings "hello" and "world" – user1080677 Aug 27 '19 at 5:24

Why don't you try something like this with find command:

find . -type f -exec grep -q 'String1' {} \; -exec grep -l 'String2' {} +

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.