LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find files containing specific text? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-files-containing-specific-text-32721/)

SurfTurtle 10-13-2002 07:37 PM

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?

trickykid 10-13-2002 07:40 PM

You could probably use any of the following commands: grep, egrep or fgrep. See the man pages for more details.

Thymox 10-13-2002 07:40 PM

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.

Thymox 10-13-2002 07:41 PM

Ooh! Split second there Drew!

SurfTurtle 10-13-2002 08:11 PM

I can only use command line tools. I do not have a GUI

neo77777 10-13-2002 10:59 PM

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

udayan 10-14-2002 07:17 AM

go over to the directory where you think is the file and then write!!
grep -r "STRING THAT YOU WANT" *

Jay_Drummond 01-05-2008 05:57 AM

Quote:

Originally Posted by udayan (Post 155126)
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"


All times are GMT -5. The time now is 08:38 AM.