LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-07-2004, 05:31 AM   #1
chamanrana
LQ Newbie
 
Registered: Aug 2003
Location: India
Distribution: Red Hat
Posts: 12

Rep: Reputation: 0
Angry 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
 
Old 02-07-2004, 05:52 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
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....
 
Old 02-07-2004, 06:41 AM   #3
cwolf
Member
 
Registered: Mar 2003
Location: Switzerland
Distribution: Sun Solaris 7/8/9, Fedora Core 3
Posts: 63

Rep: Reputation: 15
Hi,
I would use something like
Code:
grep -R -e <regexp-pattern> /
 
Old 12-01-2004, 11:47 AM   #4
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

Rep: Reputation: 15
Is there a way to search through a folder of files, find the phrase you're looking for and then show the file name?
 
Old 12-01-2004, 12:04 PM   #5
delta_simon
Member
 
Registered: Sep 2004
Location: Jakobstad Finland
Distribution: Slackware 10
Posts: 42

Rep: Reputation: 15
find <dir> -name "name"
ex find /home/user/mp3 -name "*trance*.mp3"
 
Old 12-01-2004, 12:16 PM   #6
geniarse
Member
 
Registered: May 2003
Location: UK
Distribution: Gentoo
Posts: 141

Rep: Reputation: 15
gnome search tool can do this if your after a gui (command "gnome-search-tool")
 
Old 12-01-2004, 01:23 PM   #7
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

Rep: Reputation: 15
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.
 
Old 12-01-2004, 01:59 PM   #8
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
yeah do a man grep (or just grep --help) and it'll show you how.
 
Old 12-01-2004, 05:08 PM   #9
jlangelier
Member
 
Registered: Jun 2003
Location: Denver, CO
Distribution: Debian
Posts: 95

Rep: Reputation: 15
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.


Last edited by jlangelier; 12-01-2004 at 05:14 PM.
 
Old 12-01-2004, 05:19 PM   #10
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
if only I could pipe that to the "why I love linux" thread
 
Old 12-02-2004, 10:47 AM   #11
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

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


Reply



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
Find and replace text in multiple file Bad_Bob Linux - Software 9 05-08-2008 02:31 AM
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
How to run a text file through a command prompt? Fillys6 Linux - Newbie 8 03-24-2005 02:21 PM
Command line tools to Find files with specific text naps Linux - Software 5 11-15-2004 04:46 AM
How 2 find a duplicate word in a text file cowardnewbie Programming 1 09-16-2001 11:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:10 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