Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
yes, *.log will be evaluated by the shell, not by grep. So if you have no *.log file in the current dir *.log will remain *.log and grep will try to search pattern in the file named *.log. You can check how the shell evaluates commands by: echo <command>, in your case echo grep -nH -r "pattern" *.log. The option -r has no effect if you gave an invalid file/dir argument (as *.log)
*.log is expanded by the shell as a list of files ending with that suffix, so no directories will be recursed (unless they all have the .log suffix).
You could use another grep to filter files by extension:
*.log is expanded by the shell as a list of files ending with that suffix, so no directories will be recursed (unless they all have the .log suffix).
You could use another grep to filter files by extension:
Well, I used "." as path in my example because on your grep examples you looked for files in the current directory.
Of course, if the directory to search is different than the present one, you should specify it instead of ".".
By the way, there's no need to escape the "{}".
For some reason I get:
find "." -name "*.log" -exec grep -nH "message RequestAnswerCall" {} \;
find: missing argument to `-exec'
Any ideas why?
Quote:
Originally Posted by 414N
Well, I used "." as path in my example because on your grep examples you looked for files in the current directory.
Of course, if the directory to search is different than the present one, you should specify it instead of ".".
By the way, there's no need to escape the "{}".
Must depend on your distro (or $PATH).
Works fine for me on RHEL5
Code:
find "." -name "*.log" -exec grep -nH "message RequestAnswerCall" {} \;
# Incidentally, no need to quote dir unless it has spaces
# and I prefer single quotes on filename pattern to prevent
# interpolation by shell
# it still doesn't throw an error
find . -name '*.log' -exec grep -nH "message RequestAnswerCall" {} \;
[quote]
The only thing I can get to work on Cygwin
[quote]
This(!), you should have mentioned it in your first post.
Cygwin is a port of *nix tools to MS and may vary from eg native GNU/Linux versions.
Try the man pages if it comes with those.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.