LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-29-2007, 09:00 PM   #1
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Rep: Reputation: 30
Issuing find command to search for string


Hi, is it possible to search through the entire file system or directory to look for content in a file? For instance I wanted to look up the name Joe Smoe in the /etc/passwd file but I don't know the string is in the /etc/passwd file can I issue a find to search through all files on the system looking for the string "Joe Smoe" within all files? I don't want file names but contents of the file.

Thnaks
 
Old 11-29-2007, 09:14 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,561

Rep: Reputation: 182Reputation: 182
Quote:
Originally Posted by keysorsoze View Post
Hi, is it possible to search through the entire file system or directory to look for content in a file? For instance I wanted to look up the name Joe Smoe in the /etc/passwd file but I don't know the string is in the /etc/passwd file can I issue a find to search through all files on the system looking for the string "Joe Smoe" within all files? I don't want file names but contents of the file.

Thnaks
Yes, the grep command does that. Something like:

grep smoe /home/user/*

see:
man grep

---------------
Steve Stites
 
Old 11-29-2007, 09:29 PM   #3
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Original Poster
Rep: Reputation: 30
Thanks for the fast reply jailbat. I always thought you needed to cat a file before you can grep, and I always associated the find command to searching for contents in a file. Thanks for the help.
 
Old 11-29-2007, 10:12 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
Originally Posted by keysorsoze View Post
Thanks for the fast reply jailbat. I always thought you needed to cat a file before you can grep, and I always associated the find command to searching for contents in a file. Thanks for the help.
If you find yourself using `cat' with only one argument you're
pretty much certainly abusing it. `cat' is short for conCATenate,
it's a tool that allows you to glue several files output together.

`cat oneFile | some other command' is pretty much always unnecessary,
commonly a `some other command oneFile' will do, sometimes you may
need to use a `some other command < oneFile' ...

In fact, in the case of grep you're depriving yourself of a great
lot of greps options, pertaining to the use or suppression of the
files name, for example.

When you want to know which files under /etc have the word shmoe in
them, but don't want to necessarily see the line, what you do is
a
Code:
grep -rl shmoe /etc/*
which you couldn't if you cat'ed the content of the files.


Cheers,
Tink

Last edited by Tinkster; 11-30-2007 at 01:45 AM. Reason: fix markup
 
Old 11-30-2007, 12:06 AM   #5
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Original Poster
Rep: Reputation: 30
Thanks Tink, I'll take your advice to heart I have always been using cat | grep from now on I'll just stick to grep somefile.
 
  


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
vim 'n' lynx: command line option to search for string Samsara Linux - Software 6 01-02-2013 06:36 PM
giving search-string(s) from a file to linux "find" command Fond_of_Opensource Linux - Newbie 3 02-02-2009 06:14 PM
egrep to find a command not found string romainp Linux - General 1 09-07-2007 03:30 PM
strange output whan issuing the command find juanb Linux - General 2 09-21-2005 08:36 PM
Find command using 2 search conditions nifflerX Linux - General 8 07-15-2005 01:37 PM


All times are GMT -5. The time now is 01:40 PM.

Main Menu
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