Solved

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

Posted on 2014-01-15
2
272 Views
Last Modified: 2014-01-15
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
Comment
Question by:andieje
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39782970
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
 
LVL 48

Expert Comment

by:Tintin
ID: 39783936
or simply

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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question