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.
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (11)
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 09/11/06




find . -name “filenames” -exec grep -i -H -n ‘texttofind’ {} \;
To search within sub-directories
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?
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.
Eyyyy… i found it.
Great application for developers (indeed for UBUNTU):
http://regexxer.sourceforge.net
;)
SERGIO
@Sergio:
That’s a really awesome find! I’ve always wanted an app like that… will be featuring an article about it.
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 ?
@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’ *
I used grep years ago, but I can’t make it work today:
I can’t understand why this doesn’t work:
grep -r keyword *.java
The error message says that *.java is not a file !
This used to work 30 years ago.
After issuing the command you can do
vi “filename” + “linenumber”
to open the file in the position of the occurrence
use ack-grep
you can also use: grep -R -i -n ‘function wp_content_filterize’ * to search subdirectories