Home > Back-end >  Getting all files that contains a word in a specific word set in a terminal
Getting all files that contains a word in a specific word set in a terminal

Time:04-09

What I am trying to achieve is, I want to find all files under my current root directory that contains words that are in a .txt file. In more details, I want to find all files that uses a bootstrap3 classname (any file extension).

So, basically, I will have a .txt that has a list of all bootstrap3 class names (e.g. col-md-1, container-fluid, etc.)

I've used grep -lir <word> to search the files that has the text, but what I want to do is return the files that has any of the words in a specific word set.

How would this work?

CodePudding user response:

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.  If  this  option  is
              used  multiple  times  or  is  combined with the -e (--regexp)
              option,  search  for  all  patterns  given.   The  empty  file
              contains zero patterns, and therefore matches nothing.

Something like grep -irl -f words.txt dir-to-search

  • Related