LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 12: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, 12:10 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
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, 12:12 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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, 12:14 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Try the following:
Code:
grep -lr "SMTP" --include "*.ini"
 
Old 12-11-2012, 12: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, 12: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, 12:47 PM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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, 01: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.
 
Old 02-18-2015, 07:53 AM   #9
solax
LQ Newbie
 
Registered: Feb 2015
Posts: 1

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

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

regards
solax
 
Old 02-19-2015, 03:50 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
@solax: did you read post #4 ?
 
  


Reply

Tags
grep



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:46 AM.

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
Open Source Consulting | Domain Registration