LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 05-09-2016, 06:11 PM   #1
maybebaby
LQ Newbie
 
Registered: Apr 2016
Location: Virgin Islands
Posts: 23

Rep: Reputation: Disabled
grep & find search hangups


EXERCISE:
There is a file in the /etc directory which contains the line: default=0

Search only the /etc directory; only use ONE command and do not perform a recursive search.

Command used: ____________________________________________
Filename: _____________________________________

I am logged in as root. So far I tried:
  • 1ST ATTEMPT - grep "default=0" ./* (nothing happened)
  • 2ND ATTEMPT - find /etc "default=0" ./* (listed all the files in /etc and stated find: 'default=0': No such file or directory)
  • 3RD ATTEMPT - cd /etc;grep "default=0" ./* (which returned as ./grub.conf:default=0 BUT I am confused because technically I combined two commands on one line).

Since my command was cd /etc;grep "default=0" ./* is my filename going to be ./grub.conf:default=0 since that's what it returned from my command? AND Is there a way I can do this without using cd first?

Last edited by maybebaby; 05-09-2016 at 06:27 PM.
 
Old 05-09-2016, 06:29 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,609

Rep: Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702
This works for me:

Code:
grep "default=0" /etc/*
 
1 members found this post helpful.
Old 05-09-2016, 07:52 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
Quote:
Originally Posted by maybebaby View Post
Since my command was cd /etc;grep "default=0" ./* is my filename going to be ./grub.conf:default=0 since that's what it returned from my command?
It's the file path + : + the line where grep found the matching term.
 
Old 05-10-2016, 02:40 PM   #4
maybebaby
LQ Newbie
 
Registered: Apr 2016
Location: Virgin Islands
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
It's the file path + : + the line where grep found the matching term.
I don't understand what you mean
 
Old 05-10-2016, 02:47 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
Quote:
Originally Posted by maybebaby View Post
I don't understand what you mean
Code:
 
./grub.conf:default=0  
1. File path
2. :
3. line that contains the grep match
 
1 members found this post helpful.
Old 05-10-2016, 03:19 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
As with your other question, you really need to start reading man pages for the commands you are using.
 
Old 05-10-2016, 03:54 PM   #7
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 956
Blog Entries: 3

Rep: Reputation: 391Reputation: 391Reputation: 391Reputation: 391
Quote:
Originally Posted by maybebaby View Post
Is there a way I can do this without using cd first?
In addition to reading the manual pages for grep and find, you'll want to read a little about the shell and in particular use of paths. Your shell is probably bash, but most any shell tutorial will be relevant and have a section on paths.

To get the manual pages for find and grep,

Code:
man grep
man find
The semicolon separates two 'commands' as if they were on separate lines. So your example with cd is really two on one line, not one long one. So the above could be written like this:

Code:
man grep; man find
Either way, look at the options -l and -h for grep. Read the paragraphs on them in the manual page and then try them.
 
1 members found this post helpful.
  


Reply


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
Find & grep - how to return pathes, not grep phrases ? postcd Linux - General 2 11-25-2014 01:43 PM
[SOLVED] Recursive search for strings in files with a certain date: find -name or grep -R? wolverene13 Linux - Newbie 6 10-01-2011 06:05 PM
need help .... find & grep mgra99 Linux - Newbie 2 12-31-2009 10:16 PM
Can I use GREP to find & replace text? jim.thornton Linux - Newbie 3 07-18-2008 07:36 PM
Grep search & replace strings with backslashes? ziphem Linux - Newbie 4 10-21-2007 05:36 PM


All times are GMT -5. The time now is 08:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration