LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-21-2003, 12:29 PM   #1
jojo
LQ Newbie
 
Registered: Feb 2003
Posts: 5

Rep: Reputation: 0
find a word 2


Hi All,

i need to find all the files in my system that contains a specific word.

for e.i : if a.txt contains "my_word" and c.txt contains "my_word"

so i want them to be in my_file.

the command below is not working properly..

find / -type f -exec fgrep -l "my_word" {} \;>/tmp/my_file


my_file-should contain a list of files that contains the word that i'm looking for.(a.txt,c.txt.......).

i posted this question,but i think i didnt explain myself.

hope someone can help.........

Thanks,








contains
 
Old 02-21-2003, 02:50 PM   #2
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
As I said before, in your other thread, try putting the {} and ; in single-quotes:

find / -type f -exec fgrep -l "my_word" '{}' ';' > /tmp/file_list

This works just fine for me.
 
Old 02-21-2003, 04:23 PM   #3
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Use grep -r, that goes through all files and directories recursively, so you don't need find.

Alex
 
Old 02-23-2003, 03:40 AM   #4
jojo
LQ Newbie
 
Registered: Feb 2003
Posts: 5

Original Poster
Rep: Reputation: 0
find a word problem

Hi i tried to print the command below but the following error came:


find / -type f -exec fgrep -l "my_word" '{}' ';' > /tmp/file_list

the error :
fgrep: /proc/sys/net/ipv4/route/flush: Invalid argument

so,the system found a few files,but i know there are much more files.....


hope you can help.

Thanks,
 
Old 02-23-2003, 10:55 AM   #5
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Well, the files in /proc are generally not real files. Most of them are just an interface to statistics and information about your computer. So trying to run grep on some of them may cause problems.

Keep in mind that running this command on *everything* in your entire filesystem is not the greatest idea. Not only is it going to take forever, it doesn't make any sense to search /proc or /dev for matching words. It'd be better to run find several times, on say:

find /usr ...
find /home

And so on. And keep in mind what a poster in your previous thread said, that doing it this way starts a new process for fgrep every time a file is found (which is *many* times), making it even slower.

Try what llama_meme said - use grep -r

Use the man pages!
 
  


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
find and replace answer word? matarodi Linux - General 0 10-27-2005 02:51 PM
find a word within any files Linh Linux - General 6 06-06-2004 12:15 PM
how can i find all include special word in a dir henryluo Linux - General 4 11-12-2003 11:56 AM
Find a word. jojo Programming 6 02-21-2003 12:27 PM
How 2 find a duplicate word in a text file cowardnewbie Programming 1 09-17-2001 12:57 AM


All times are GMT -5. The time now is 09:05 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration