LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-30-2008, 11:29 PM   #1
pranavojha
Member
 
Registered: Feb 2006
Location: Bangalore, India
Distribution: Fedora Core 3
Posts: 68

Rep: Reputation: 15
Exclamation How to search for file with particular text


Hi,

I was asked to search for a file that contains the text "error:". I am not aware where that file is or what it's name is.

Someone suggested using

Code:
grep "error:" *
Which can look for a file within a particular directory only. How about looking for a file with text in the whole filesystem?
 
Old 10-31-2008, 12:11 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Code:
grep -R 'error:' /*
 
Old 11-01-2008, 01:54 AM   #3
pranavojha
Member
 
Registered: Feb 2006
Location: Bangalore, India
Distribution: Fedora Core 3
Posts: 68

Original Poster
Rep: Reputation: 15
hi

Is that the best way to look for a file containing specified text through commands ?
 
Old 11-01-2008, 01:58 AM   #4
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
What more do you want? Grep is designed for finding strings in files.
 
Old 11-01-2008, 10:47 AM   #5
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
If you know or can guess a few other things about the file, you can use find to look for only files with certain properties, and reduce the search time.

e.g. with this command, you'll only search regular files with a ".txt" extension less than 50k in size:
Code:
find / -type f -name "*.txt" -size -50k -exec grep 'error:' \{\} \+
check out man find for other options.
 
Old 11-01-2008, 11:12 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by pranavojha View Post
Is that the best way to look for a file containing specified text through commands ?
Why not talk to the person who requested this and get a better definition of the problem? For example, what directories need to be searched?

There is often no "best way" to do something in Linux.......
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to search for a string in a text file using wildcards(*,?) tnjones Programming 2 08-23-2008 07:04 AM
How to search within text file 666 Linux - General 2 05-09-2007 02:26 PM
Need command to search and replace text in file acascianelli AIX 12 04-11-2007 08:16 PM
Need to search for *last* occurrance in a text file ericcarlson Linux - Software 1 09-11-2004 02:08 PM
How do you search for a file in text mode? cyberkid12 Linux - General 7 12-21-2002 12:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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