Subscribe to How-To Geek

Find files containing search terms on Ubuntu

To find files containing keywords, linux has a powerful command called grep, which you can use to find the lines inside any file or a list of files. I use this very often to find a function declaration in a set of php files that I’m unfamiliar with.

Let’s say we are looking for the definition of a function called wp_content_filterize, and we don’t know where to start. Let’s try using grep…

grep -i -n ‘function wp_content_filterize’ *

We should see the output right on the console

functions.php:18:function wp_content_filterize($thefilter) {

Now we know that the function definition is found in the file functions.php, on line 18.

| More
This article was originally written on 09/11/06 Tagged with: Ubuntu

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:

Comments (7)

  1. Ajo Paul

    find . -name “filenames” -exec grep -i -H -n ‘texttofind’ {} \;

    To search within sub-directories

  2. Mark Olech

    I use windows 2000 and xp. I need a way to search withing a list of text files for a specific number. I want to then take the search results and output the lines of text containing this number to a text file, or possibly an html document that will then open up. Basically, I need to output the results into some form of data that I can easily read. Are there any free programs that I can use to do this or do you have any ideas?

  3. imasdeweb.com

    Now i’m using UBUNTU-LINUX, but before -when i worked in winXP- one of my preferred applications were Agent Ransack (freeware). Here is its offcial webpage:

    http://www.mythicsoft.com/agentransack/

    This application is the only i would like to have in UBUNTU. Once it is installed, you simply do click with secondary button mouse over a directory and click on “Search with Agent Ransack”, and… fantastic: it find very rapidly all files (indicating the exact line) wich contains the string you search!!

    I would like to know if exists some like this for UBUNTU ;) ))

    SERGIO R.

  4. imasdeweb.com

    Eyyyy… i found it.
    Great application for developers (indeed for UBUNTU):

    http://regexxer.sourceforge.net

    ;)

    SERGIO

  5. The Geek

    @Sergio:

    That’s a really awesome find! I’ve always wanted an app like that… will be featuring an article about it.

  6. speed

    how do I find some text only in some specific files in a directory, lets say I want grep to look only in .c files only ?

  7. Anderson

    @Ajo :
    In fact you can use -R option on grep to do it recursively (maybe it’s a recent thing, this post is back to 2007, I know)

    grep -R ‘pattern’ *


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Our Friends
Getting Started


About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
mDNSResponder.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
conhost.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.