Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-05-2005, 07:20 AM   #1
LQ Newbie
Registered: Nov 2003
Location: NW Indiana
Distribution: Ubuntu 6.06 LTS
Posts: 18

Rep: Reputation: 0
how do i search files for a particular string?

from the console, how do i find a which files contain a particular string? i know that i could easily do it in X easily, but I'd like to learn how to do it from the command prompt.
doesn't it involve using the grep command? i tried reading the man pages for the grep command but i could make any heads or tails on how do search all files in a directory tree.
so could someone give me some examples?

thank you.
Old 07-05-2005, 07:49 AM   #2
Registered: Apr 2004
Location: Newcastle, UK
Distribution: Slackware 10.2
Posts: 134

Rep: Reputation: 15
This is how to find a sting in a particular text file

less textfile | grep "string "
Old 07-05-2005, 07:53 AM   #3
Registered: Jan 2004
Distribution: Debian etch
Posts: 202

Rep: Reputation: 30
or if you want to search a directory

grep string -r path
Old 07-05-2005, 07:55 AM   #4
LQ Newbie
Registered: Jun 2005
Posts: 4

Rep: Reputation: 0
You can use the grep command to find all the files having a partcular string. The syntax for the same is as follows

grep " search string" -r path

it will list all the files having the search string


Last edited by singhalyogesh; 07-05-2005 at 07:57 AM.
Old 07-05-2005, 06:46 PM   #5
LQ Newbie
Registered: Nov 2003
Location: NW Indiana
Distribution: Ubuntu 6.06 LTS
Posts: 18

Original Poster
Rep: Reputation: 0
thank you very much.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to search for a string from all the files on the harddisk? Akhran Linux - Newbie 8 09-13-2005 07:09 AM
search for a string in c alaios Programming 1 07-07-2005 05:50 PM
C....Search a string for a string Scrag Programming 4 06-14-2004 05:15 PM
[c++] Search in a string hylke Programming 5 06-14-2004 12:20 PM
search for my string alaios Linux - General 6 05-08-2004 02:32 PM

All times are GMT -5. The time now is 03:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration