LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-13-2002, 07:37 PM   #1
SurfTurtle
LQ Newbie
 
Registered: Sep 2002
Distribution: RedHat Linux 7.3
Posts: 3

Rep: Reputation: 0
How to find files containing specific text?


I have misplaced a file and I don't even remember its filename. But I do know some of the text inside this file. So is there a way I could search for files containing that text?
 
Old 10-13-2002, 07:40 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
You could probably use any of the following commands: grep, egrep or fgrep. See the man pages for more details.
 
Old 10-13-2002, 07:40 PM   #3
Thymox
Senior Member
 
Registered: Apr 2001
Location: Plymouth, England.
Distribution: Mostly Debian based systems
Posts: 4,368

Rep: Reputation: 64
There's probably a really easy way to do it from the command line, but I can't think of any, so kfind will have to do for my suggestion.
 
Old 10-13-2002, 07:41 PM   #4
Thymox
Senior Member
 
Registered: Apr 2001
Location: Plymouth, England.
Distribution: Mostly Debian based systems
Posts: 4,368

Rep: Reputation: 64
Ooh! Split second there Drew!
 
Old 10-13-2002, 08:11 PM   #5
SurfTurtle
LQ Newbie
 
Registered: Sep 2002
Distribution: RedHat Linux 7.3
Posts: 3

Original Poster
Rep: Reputation: 0
I can only use command line tools. I do not have a GUI
 
Old 10-13-2002, 10:59 PM   #6
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
Well than grep and find combined should work
find / -type f -exec grep -i pattern '{}' \; -print
it will take some time but if you know approximatelly directory where the file might be you can shorten the path just to start from this directory, suppose the file is somewhere in /home ->
find /home -type f -exec grep -i pattern '{}' \; -print

Last edited by neo77777; 10-13-2002 at 11:02 PM.
 
Old 10-14-2002, 07:17 AM   #7
udayan
Member
 
Registered: Apr 2002
Location: India
Distribution: Linux Redhat 7.0
Posts: 62

Rep: Reputation: 16
go over to the directory where you think is the file and then write!!
grep -r "STRING THAT YOU WANT" *
 
1 members found this post helpful.
Old 01-05-2008, 05:57 AM   #8
Jay_Drummond
Member
 
Registered: Jul 2005
Location: Ohio
Distribution: CentOS 4 & 5, Ubuntu 7.04 & 7.10
Posts: 38

Rep: Reputation: 15
Quote:
Originally Posted by udayan View Post
go over to the directory where you think is the file and then write!!
grep -r "STRING THAT YOU WANT" *
You might also want to add the -l option so that only the file names are printed. That way if you find a file that has a millon occurences of your search string it will only print the file name and not the million lines that match inside the file.

grep -rl "STRING THAT YOU WANT" *

Also note that this does not search hidden directories. The find examples given previously do. I prefer to use xargs in combination with find and grep since it doesn't suffer any size limitations. These find examples will show you the names of the files that contain the pattern or "STRING THAT YOU WANT"

find / -type f | xargs grep -l pattern

or from the current working directory

cd /somedirectory
find . -type f | xargs grep -l "STRING THAT YOU WANT"
 
  


Reply

Tags
command, help, linux



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
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
du on specific files from find command (use xargs?) fireman949 Linux - Software 2 07-10-2005 01:42 AM
Command line tools to Find files with specific text naps Linux - Software 5 11-15-2004 04:46 AM
how to find a specific file over several *.tgz files eeyoree Slackware 6 08-09-2004 12:37 AM
Find files, directories that are own by specific user mikeshn Linux - General 2 02-12-2004 03:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:54 PM.

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