LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-24-2015, 07:02 PM   #1
Huamin
Member
 
Registered: May 2011
Posts: 562

Rep: Reputation: 12
Problem to the command


Hi,
what to adjust below

[root@hpi5 /]# find . -type f -exec grep -il "192.168" {} > log.txt
find: missing argument to `-exec'
[root@hpi5 /]#

as I want to search all files (including sub-folders) having one specific string inside.
 
Old 11-24-2015, 07:11 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
find . -type f -exec grep 192.168 {} \; > log.txt

Last edited by Habitual; 11-24-2015 at 07:12 PM.
 
Old 11-24-2015, 07:11 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Huamin View Post
Hi,
what to adjust below

[root@hpi5 /]# find . -type f -exec grep -il "192.168" {} > log.txt
find: missing argument to `-exec'
[root@hpi5 /]#

as I want to search all files (including sub-folders) having one specific string inside.
Read the man page on the find command and you'll see. Pay attention to the recursive flag. Read the "Question Guidelines" link in my posting signature.

You have been here for FOUR YEARS, and have close to 500 posts. You should know by now to do basic research on your own, and show some effort of your own. Asking others to look things up for you and spoon feed you repeatedly isn't nice.
 
Old 11-24-2015, 10:12 PM   #4
Huamin
Member
 
Registered: May 2011
Posts: 562

Original Poster
Rep: Reputation: 12
TBOne,
Forum is to share knowledge and experience (as human being cannot know everything and this is why many kind of Forums do exist on the planet!), and I did contribute in the same way in some other places, like

https://social.msdn.microsoft.com/Fo...HuaMin2020Chen

Can you please calm down and be sincere, in all of the times?

Last edited by Huamin; 11-24-2015 at 10:14 PM.
 
1 members found this post helpful.
Old 11-25-2015, 06:32 AM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Huamin:
There are several variations of grep'ing you should now about...
Let's say you're only interested in find the file names where 192.168 exists, you
could then use
Code:
find . -type f -exec grep -ls 192.168 {} \; > files.txt
Real Example:
Code:
sudo grep -ls pam_unix  /var/log/* -R
/var/log/auth.log
/var/log/auth.log.1
Please bookmark this excellent site for future reference:
It's where I learned to "cut my teeth" on most things command-line

Understand our position also, we get 1000s of visitors every day asking the same basic questions.
90% of their answers are found in the man pages and are considered basic.

Search is your friend.
Have a great day!
 
1 members found this post helpful.
Old 11-25-2015, 08:04 AM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Quote:
Originally Posted by Huamin View Post
TBOne,
Forum is to share knowledge and experience (as human being cannot know everything and this is why many kind of Forums do exist on the planet!), and I did contribute in the same way in some other places, like

https://social.msdn.microsoft.com/Fo...HuaMin2020Chen

Can you please calm down and be sincere, in all of the times?
Tend to agree with you on this one it's easy enough to miss somthing like a trailing semi-colon and the command was mostly OK so I think a bit of an over reaction on TBOne' part, but then again we all have off days where everything anyone does just gets our back up.
 
Old 11-25-2015, 08:45 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Huamin View Post
TBOne,
Forum is to share knowledge and experience (as human being cannot know everything and this is why many kind of Forums do exist on the planet!), and I did contribute in the same way in some other places, like

https://social.msdn.microsoft.com/Fo...HuaMin2020Chen Can you please calm down and be sincere, in all of the times?
First, I was (and am) calm. Secondly, what you do anywhere else, doesn't matter in relation to what you do HERE. Third, and most importantly, my comment is valid. After FOUR YEARS and close to 500 posts, why can you not read the man pages yourself? There are over TWO MILLION hits in Google for "how to find files in all subdirectories in linux". What prevented you from looking this up? Or better, reading some of your OTHER threads, asking how to find files:
http://www.linuxquestions.org/questi...nd-4175552504/
http://www.linuxquestions.org/questi...le-4175555893/

Again, look back at your posting history. These:
http://www.linuxquestions.org/questi...le-4175556409/
http://www.linuxquestions.org/questi...os-4175558002/
http://www.linuxquestions.org/questi...ql-4175544447/
http://www.linuxquestions.org/questi...le-4175542731/
http://www.linuxquestions.org/questi...le-4175543582/
http://www.linuxquestions.org/questi...le-4175543090/

..are some good examples of things you could have easily looked up.
 
Old 11-25-2015, 08:50 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by Huamin View Post
as I want to search all files (including sub-folders) having one specific string inside.
and what about:
Code:
grep -irl "pattern" .
?
 
1 members found this post helpful.
Old 11-26-2015, 12:52 AM   #9
Huamin
Member
 
Registered: May 2011
Posts: 562

Original Poster
Rep: Reputation: 12
Pan64,
I cannot find out the relevant by this

grep -irl "192.168" .
 
Old 11-26-2015, 02:52 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I do not really understand you again. This should give [almost] the same result as your first attempt (with find and grep). If you need another kind of output see the man page of grep and check the flags -n -l -c (and any other one you like)
 
Old 11-26-2015, 09:38 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by pan64 View Post
I do not really understand you again. This should give [almost] the same result as your first attempt (with find and grep). If you need another kind of output see the man page of grep and check the flags -n -l -c (and any other one you like)
I wish you luck in getting the OP to read man pages.
 
Old 11-26-2015, 09:52 AM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Huamin View Post
Pan64,
I cannot find out the relevant by this

grep -irl "192.168" .
Then it doesn't exist, or you did it incorrectly.
You realize that "." is the current directory and grep -irl will search from the current directory down/under?
And doing this from the / directory becomes most inefficient.

Test it out. Learn from your experience.
Code:
echo "192.168" >> $HOME/test.txt
then issue:
Code:
grep -irl "192.168" $HOME
lots of things fly by here, so here's the 'hit'
Code:
/home/jj/test.txt
Your username, of course will not be "jj"

Last edited by Habitual; 11-26-2015 at 10:10 AM.
 
Old 11-26-2015, 08:11 PM   #13
Huamin
Member
 
Registered: May 2011
Posts: 562

Original Poster
Rep: Reputation: 12
Hi,
I do not know it does keep waiting below
https://dl.dropboxusercontent.com/u/40211031/tt392.png

for long time
 
Old 11-26-2015, 08:52 PM   #14
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Huamin View Post
Hi,
I do not know it does keep waiting below
https://dl.dropboxusercontent.com/u/40211031/tt392.png

for long time
You forgot the dot. The way you run grep it reads from standard input, not from the current directory.
As pan64 said, read the man page. It's not very useful to blindly follow what other people tell you; you also need to understand what those commands do.
 
Old 11-26-2015, 10:28 PM   #15
Lexus45
Member
 
Registered: Jan 2010
Distribution: Debian, Centos, Ubuntu, Slackware
Posts: 361
Blog Entries: 3

Rep: Reputation: 48
Hello.

Besides, it is more secure to use 'execdir' instead of 'exec' in find command.
 
  


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
Problem with the command Huamin Linux - Software 6 06-12-2014 06:30 PM
problem with auditreduce command and praudit command preetishetty Linux - Security 0 12-03-2007 08:24 AM
Problem with at command xav.vijay Linux - Newbie 7 08-05-2007 03:32 AM
at Command Problem BBPS Linux - Software 2 09-06-2006 05:23 AM
problem with dd command ? MaaSTaaR Linux - General 5 06-25-2006 07:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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