LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why does grep return "No such file or directory"? (https://www.linuxquestions.org/questions/linux-newbie-8/why-does-grep-return-no-such-file-or-directory-4175440996/)

lwang3rock 12-11-2012 12:06 PM

Why does grep return "No such file or directory"?
 
I copied the following from my linux console.

grep -lr "SMTP" *.ini
grep: *.ini: No such file or directory

I wanted to search recursively under current location in files with extenstion .ini
Actually there are files that contain "SMTP" under this directory. But I got the above error message.
What is wrong? I am using centos 6.

Thanks,
3rock

linosaurusroot 12-11-2012 12:10 PM

You have no files matching *.ini in the current directory.

untested commands:
Code:

grep -lr SMTP .
Code:

find . -type f -name '*.ini' -exec grep -l SMTP {} \;

shivaa 12-11-2012 12:12 PM

You're not running it recurrsively, but only searching in current directory. For a recurrsive search, use "./" before *.ini, as:
Code:

grep -lr "SMTP" ./*.ini
Well, instead of simple grep, you should better use find cmd.

sycamorex 12-11-2012 12:14 PM

Try the following:
Code:

grep -lr "SMTP" --include "*.ini"

lwang3rock 12-11-2012 12:29 PM

Why does grep return "No such file or directory"?
 
I guess you can do either

grep -r "SMTP" * (searching under current directory and sub dir)

or

grep -l "SMTP" *.ini

but you can't mix the two commands. That is why it failed doing what I meant to do.

3rock

lwang3rock 12-11-2012 12:32 PM

Why does grep return "No such file or directory"?
 
I tried this, and get the similar error
[ipbx@lab33 ~]$ grep -lr "SMTP" ./*.ini
grep: ./*.ini: No such file or directory

---------- Post added 12-11-12 at 01:33 PM ----------

grep -lr "SMTP" --include "*.ini"

seems taking forever.

shivaa 12-11-2012 12:47 PM

Alright, first make sure that is there really any file with extension .ini exists in your current directory? Once invoke:
Code:

find . -name "*.ini" -print
find command might take some time in searching, so wait till it gets finished. And if it lists any files, then invoke:
Code:

find . -name "*.ini" -print | xarge grep -lr "SMTP"
OR
find . -name "*.ini" -exec grep -lr "SMTP" {} \;


lwang3rock 12-11-2012 01:32 PM

find command works for me.
I didn't figure out to do it using grep only without using find command.

solax 02-18-2015 07:53 AM

Although it is an old thread, I would like to add my solution to this:

grep -lr "SMTP" --include "*.ini" .

regards
solax

chrism01 02-19-2015 03:50 AM

@solax: did you read post #4 ?


All times are GMT -5. The time now is 05:08 AM.