LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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



Reply
 
Search this Thread
Old 12-11-2012, 01:06 PM   #1
lwang3rock
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Rep: Reputation: Disabled
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
 
Old 12-11-2012, 01:10 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 870
Blog Entries: 2

Rep: Reputation: 217Reputation: 217Reputation: 217
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 {} \;
 
Old 12-11-2012, 01:12 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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.
 
Old 12-11-2012, 01:14 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,596
Blog Entries: 1

Rep: Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046
Try the following:
Code:
grep -lr "SMTP" --include "*.ini"
 
Old 12-11-2012, 01:29 PM   #5
lwang3rock
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-11-2012, 01:32 PM   #6
lwang3rock
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
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.
 
Old 12-11-2012, 01:47 PM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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" {} \;
 
Old 12-11-2012, 02:32 PM   #8
lwang3rock
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
find command works for me.
I didn't figure out to do it using grep only without using find command.
 
  


Reply

Tags
grep


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 07:58 AM
How to do "grep" on each file in directory grob115 Programming 8 07-07-2010 06:16 AM
Grep in bash script returns "No such file or directory", works manually gizza23 Programming 7 02-25-2010 05:37 PM
Problem "$value=`mpstat 1 1 | grep "Average"`;" Alias pipe return nothing adamlucansky Linux - General 8 09-25-2009 08:26 AM
"grep: /etc/issue: No such file or directory" hunter_one Linux - Software 6 10-15-2003 04:27 PM


All times are GMT -5. The time now is 02:08 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration