Find all files matching 'name' on linux system, and search with them for 'text'

前端 未结 5 1515
猫巷女王i
猫巷女王i 2020-12-24 12:04

I need to find all instances of \'filename.ext\' on a linux system and see which ones contain the text \'lookingfor\'.

Is there a set of linux command line operation

5条回答
  •  情深已故
    2020-12-24 12:43

    Try:

    find / -type f -name filename.ext -exec grep -H -n 'lookingfor' {} \;
    

    find searches recursively starting from the root / for files named filename.ext and for every found occurrence it runs grep on the file name searching for lookingfor and if found prints the line number (-n) and the file name (-H).

提交回复
热议问题