LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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, Lubuntu, FreeBSD
Posts: 3,930
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 Squeeze
Posts: 5,739

Rep: Reputation: 298Reputation: 298Reputation: 298
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: 12,050

Rep: Reputation: 970Reputation: 970Reputation: 970Reputation: 970Reputation: 970Reputation: 970Reputation: 970Reputation: 970
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, Lubuntu, FreeBSD
Posts: 3,930
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
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,453

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration