Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.
Linux

Linux Search From Shell Using Grep Find Xargs

The find command is used to find files in a Unix/Linux system. The grep command is used to find text within files and output. The xargs utility is used to combine commands together. This is a demonstration of using all three to search for specific text within files recursively through the directory tree.

find . | xargs grep my string -risl

r tells the system to perform the search recursively.
i tells it to ignore cases.
s tells it to suppress error messages.
l lets it know we only want matching filenames.

You can also send the output to a file since sometimes the lists can be very long. Once in the file it can easily be browsed using VIM or you can even grep it again.

find . | xargs grep my string -risl > /mylist.grep

Related posts:

  1. Resize Images From Linux Shell using imagemagick
  2. linux i discovered umask and sgid for default file/directory permissions
  3. linux using the cat command to append files together

Tags: , ,

2 Responses to “Linux Search From Shell Using Grep Find Xargs”

  1. Randy says:

    Wouldn’t it be easier to type “grep -ril “search term?
    r = recursive
    i = ignore case
    l = only list the file name not “file name:matching line?

    sorry it should read “grep -ril search_term *?

  2. Hi, i think that i saw you visited my site so i came to “return the favor”.I’m trying to find things to enhance my website!I suppose its ok to use some of your ideas!!

Leave a Reply