[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

command to search all files in folders and sub folders for a series of strings

Hi

I want to look for a series of strings in a set of files and i'm not used to using the command line. In other words I want to look for 'term1' or 'term2' in all the files in a directory and its sub directory. I'd like to pipe the results into a text file too.

I havent used limux for ages so I don't know whether to use find or grep or awk.

Any advice much appreciated

thanks
0
andieje
Asked:
andieje
1 Solution
 
woolmilkporcCommented:
find /directory -type f | xargs grep -E 'term1|term2' > outputfile

The above will show the matching content along with the filenames. If you want to see just the names of files with matching content, but not the content itself use

find /directory -type f | xargs grep -El 'term1|term2' > outputfile

/directory is the directory where the search should start.
0
 
TintinCommented:
or simply

grep -Er 'term1|term2' /directory >outputfile
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now