LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 06-03-2004, 04:35 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
find a word within any files


find a word within any files.

Below is a command to find the name of the files that contains
the word setclientconfig. It went into an infinte loop when it hit the
directory /proc . It could be because there is too many subdirectories
underneath the /proc directory.

1) How do I issue the same command but tells Linux not to search
in the directory /proc ?
=========================

find / -type f | xargs grep "setclientconfig"


grep: Starter: No such file or directory
grep: Edition.lnk: No such file or directory
find: /proc/24890/fd/4: No such file or directory
find: /proc/27519/fd: No such file or directory
find: /proc/27520/fd: No such file or directory
find: /proc/27521/fd: No such file or directory
find: /proc/27522/fd: No such file or directory
find: /proc/27523/fd: No such file or directory
find: /proc/27529/fd: No such file or directory
find: /proc/27605: No such file or directory
grep: /proc/sys/net/ipv4/route/flush: Invalid argument

Last edited by Linh; 06-03-2004 at 04:37 PM.
 
Old 06-03-2004, 04:44 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
I think it is happening because you are looking at files that do not exist by the time they come to be grepped. What about using:
find / -type f -exec grep "setclientconfig" {} \;
 
Old 06-03-2004, 04:57 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,305
Blog Entries: 54

Rep: Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857
/proc is a virtual FS, use -xdev switch.
 
Old 06-03-2004, 05:02 PM   #4
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

Hi david_ross, and thank you for your help.

for the command find / -type f -exec grep "setclientconfig" {} \;

1) What is the option {} \; do ?
 
Old 06-03-2004, 05:31 PM   #5
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply to unSpawn

Hi unSpawn. thank you for your help. Do you mean to use it like this

find / -type f -xdev grep "setclientconfig" {} \;

as oppose to

find / -type f -exec grep "setclientconfig" {} \;
 
Old 06-03-2004, 05:53 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,305
Blog Entries: 54

Rep: Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857Reputation: 2857
"man find" and you'll see "-xdev" is just another switch you can add.
You'll want to run find / -type f -xdev -exec grep "setclientconfig" {} \; because w/o the "-exec" switch "find" won't run the command.
 
Old 06-06-2004, 11:15 AM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Just to expand on unSpawn's answer:
{} is replaced by the result of the search (the matching file names)
\; is used to end the exec command. Using a semi colon on it's own would only end the find command so it must be escaped.
 
  


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 On
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 01:51 PM
how can i find all include special word in a dir henryluo Linux - General 4 11-12-2003 10:56 AM
find a word 2 jojo Programming 4 02-23-2003 09:55 AM
Find a word. jojo Programming 6 02-21-2003 11:27 AM
How 2 find a duplicate word in a text file cowardnewbie Programming 1 09-16-2001 11:57 PM


All times are GMT -5. The time now is 09:40 PM.

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