LinuxQuestions.org
Visit Jeremy's Blog.
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 05-09-2016, 05: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 05:27 PM.
 
Old 05-09-2016, 05:29 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
This works for me:

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

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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, 01: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, 01:47 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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, 02:19 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As with your other question, you really need to start reading man pages for the commands you are using.
 
Old 05-10-2016, 02:54 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
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



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 12: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 05:05 PM
need help .... find & grep mgra99 Linux - Newbie 2 12-31-2009 09:16 PM
Can I use GREP to find & replace text? jim.thornton Linux - Newbie 3 07-18-2008 06:36 PM
Grep search & replace strings with backslashes? ziphem Linux - Newbie 4 10-21-2007 04:36 PM

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

All times are GMT -5. The time now is 06:40 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
Open Source Consulting | Domain Registration