Solved

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

Posted on 2014-01-15
2
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

752 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