LinuxQuestions.org

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

lwang3rock 12-11-2012 01: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 01: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 01: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 01:14 PM

Try the following:
Code:

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

lwang3rock 12-11-2012 01: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 01: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 01: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 02:32 PM

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


All times are GMT -5. The time now is 05:58 PM.