LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-19-2005, 10:59 AM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
how to grep a specifc directory


Hi,

consider I want to grep the /root directory for the keyword "panoply",while I'm at /mnt/usb directory.

how do I do it, without CD'ing to the /root directory first
 
Old 12-19-2005, 11:24 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Errmmm....

grep panoply /root/*
 
Old 12-19-2005, 08:29 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by irfanhab
Hi,

consider I want to grep the /root directory for the keyword "panoply",while I'm at /mnt/usb directory.

how do I do it, without CD'ing to the /root directory first
You don't "grep a directory"---you read one or more files and pass them to grep. If you use the fully-qualified filename, you can read it a grep it from anywhere.
Are you looking for filenames or content?

For filenames, you need ls <path> | grep keyword

For content, cat <path/filename> |grep keyword
 
Old 12-19-2005, 08:44 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by pixellany
Are you looking for filenames or content?

For filenames, you need ls <path> | grep keyword

For content, cat <path/filename> |grep keyword
Eh?

Quote:
For filenames, you need ls <path> | grep keyword
ls *keyword*

Quote:
For content, cat <path/filename> |grep keyword
grep keyword path/filename


Cheers,
Tink
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
grep: /usr/lib/libglib-2.0.la: No such file or directory FirstTimeUser Linux - Software 9 10-15-2003 09:53 PM
"grep: /etc/issue: No such file or directory" hunter_one Linux - Software 6 10-15-2003 03:27 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:48 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