LinuxQuestions.org
Review your favorite Linux distribution.
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 08-05-2007, 08:54 PM   #1
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Rep: Reputation: 15
finding files


Hi,

If I want to find all files on my box which contain a certain word, what should I do?

Thanks,

Noha
 
Old 08-05-2007, 09:03 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by nmansour
files on my box which contain a certain word...
In the filename itself, or in the contents (of, say, an ascii text file)?

If the former, find or locate (if installed) will do it.

If the latter, a recursive grep from the appropriate starting point will do it.
 
Old 08-05-2007, 09:33 PM   #3
Four
Member
 
Registered: Aug 2005
Posts: 298

Rep: Reputation: 30
I would like to know how to search inside files. But for using find do this

list files of "filename"
find /directory/where/you/want/to/search/ -type f | grep "filename"

List directories of "filename"
find /directory/where/you/want/to/search/ -type d | grep "filename"
 
Old 08-05-2007, 09:44 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Quote:
If I want to find all files on my box which contain a certain word, what should I do?
find / -type f | xargs grep "search string"

You will have to run it as root because of the many directories/files to which the normal user doesn't have access.
Replace "search string" with the word/phrase you want to find.
 
Old 08-05-2007, 10:10 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Also use -H on the greps
 
Old 08-06-2007, 12:32 AM   #6
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Original Poster
Rep: Reputation: 15
This is the command I used, and this is what I was given, what does this mean?

find / -type f | xargs grep -H "million"
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

Noha
 
Old 08-06-2007, 06:27 AM   #7
Fond_of_Opensource
Member
 
Registered: May 2006
Posts: 55

Rep: Reputation: 15
Use this command.


# find / -exec -H grep "your_pattern_string" {} \;
 
Old 08-06-2007, 08:54 AM   #8
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Original Poster
Rep: Reputation: 15
I did not find the file which contains the word "million".
It is a regular file and I am sure it is somewhere in my box.

Thanks,

Noha
 
Old 08-06-2007, 09:07 AM   #9
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by nmansour
I did not find the file which contains the word "million".
It is a regular file and I am sure it is somewhere in my box.
A 'regular' file in that it's an ascii text file? (As opposed to a binary OOo or abiword doc?)

If you have no clue where it could be, I'd use:
# grep -IRHi 'million' /*

If you have some idea about which subdirectory it would be under, that'll speed the search up for you.
 
Old 08-06-2007, 09:11 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Maybe the word "million" is not lower-case? Following one of the examples above, you can try
Code:
find / -type f -exec grep -Hiw million {} \;
See man grep for details about -i and -w options. Searching from / can take a long time, yet. Hope this helps.
 
  


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
Finding files and then finding content within those files... Maeltor Linux - Software 5 03-13-2007 12:06 PM
finding files in C++ poeta_boy Programming 2 07-11-2004 01:25 AM
Finding files brentos Linux - General 3 03-22-2004 08:24 PM
Finding files Nicksan Linux - Software 3 06-30-2003 07:16 PM
Finding files of particular sizes jISV Linux - General 1 04-30-2002 12:06 PM

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

All times are GMT -5. The time now is 10:43 AM.

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