Solved

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

Posted on 2014-01-15
2
270 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now