LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Problem to the command (https://www.linuxquestions.org/questions/linux-software-2/problem-to-the-command-4175559810/)

Huamin 11-24-2015 07:02 PM

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.

Habitual 11-24-2015 07:11 PM

Code:

find . -type f -exec grep 192.168 {} \; > log.txt

TB0ne 11-24-2015 07:11 PM

Quote:

Originally Posted by Huamin (Post 5454840)
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.

Huamin 11-24-2015 10:12 PM

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?

Habitual 11-25-2015 06:32 AM

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!

Keith Hedger 11-25-2015 08:04 AM

Quote:

Originally Posted by Huamin (Post 5454910)
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.

TB0ne 11-25-2015 08:45 AM

Quote:

Originally Posted by Huamin (Post 5454910)
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.

pan64 11-25-2015 08:50 AM

Quote:

Originally Posted by Huamin (Post 5454840)
as I want to search all files (including sub-folders) having one specific string inside.

and what about:
Code:

grep -irl "pattern" .
?

Huamin 11-26-2015 12:52 AM

Pan64,
I cannot find out the relevant by this

grep -irl "192.168" .

pan64 11-26-2015 02:52 AM

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)

TB0ne 11-26-2015 09:38 AM

Quote:

Originally Posted by pan64 (Post 5455559)
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.

Habitual 11-26-2015 09:52 AM

Quote:

Originally Posted by Huamin (Post 5455532)
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"

Huamin 11-26-2015 08:11 PM

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

for long time

berndbausch 11-26-2015 08:52 PM

Quote:

Originally Posted by Huamin (Post 5455780)
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.

Lexus45 11-26-2015 10:28 PM

Hello.

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


All times are GMT -5. The time now is 06:00 AM.