LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Command to find file with text (https://www.linuxquestions.org/questions/linux-software-2/command-to-find-file-with-text-143277/)

chamanrana 02-07-2004 05:31 AM

Command to find file with text
 
Hello there,
is there a command in Linux to find a file (searching in the whole disk) with some text (of the file) which I will explicit in the search? something like:
find "text inside the file" in all the files

Thanks!
x:tisk:

b0uncer 02-07-2004 05:52 AM

hmm....haven't done ever (as finding all the files on one's disk takes a hell of a long time ;) heheh) but here's some starting things:

"cat" prints out the contents of a file, like "cat foo.txt" prints what's inside foo.txt and "cat /*/*" might then print out everything in everywhere? not sure.
"grep" cuts off and prints only the parts that are given, for example "cat foo.txt | grep you" would first read through file foo.txt, then print out every line which has the string "you" inside it (like you, you're, yours, fdsajlkfdsyoufdlask and so on) :)

I don't know any ready program...perhaps there is, perhaps not. You might want to try combining different commands to success....

cwolf 02-07-2004 06:41 AM

Hi,
I would use something like
Code:

grep -R -e <regexp-pattern> /

MadTurki 12-01-2004 11:47 AM

Is there a way to search through a folder of files, find the phrase you're looking for and then show the file name? :scratch:

delta_simon 12-01-2004 12:04 PM

find <dir> -name "name"
ex find /home/user/mp3 -name "*trance*.mp3"

geniarse 12-01-2004 12:16 PM

gnome search tool can do this if your after a gui (command "gnome-search-tool")

MadTurki 12-01-2004 01:23 PM

I'm using Darwin so, no gnome gui for me. - not quite what I'm looking for delta - I want to show the name of the file that contains the string.

ror 12-01-2004 01:59 PM

yeah do a man grep (or just grep --help) and it'll show you how.

jlangelier 12-01-2004 05:08 PM

Code:

        find . -name *.txt | xargs grep -l 'text-to-find'

... where . is the directory specification (this one starts at the current directory)
... where *.txt is the filespec of files to search
... where 'text-to-find' is the text you want to find inside thefiles.

But sometimes you'll find so many files it'll scroll away. Here's what I do:

Code:

        find . -name *.txt | xargs grep -l 'text-to-find'  | gvim -
... which will pipe the resulting file names to a new instance of VIM.


ror 12-01-2004 05:19 PM

if only I could pipe that to the "why I love linux" thread :)

MadTurki 12-02-2004 10:47 AM

Brilliant! Thank you. I just did a | more at the end of it. Thanks all!


All times are GMT -5. The time now is 05:22 AM.