LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-16-2005, 06:45 AM   #1
neocookie
Member
 
Registered: Apr 2004
Location: Leeds, UK
Distribution: FC1, FC2, Debian
Posts: 308

Rep: Reputation: 30
Find in files on linux?


Hi all

Is there any way I can search the whole linux file structure to look for a specific string in a file? I've lost something and can only remember the title I added.

Cheers.
 
Old 12-16-2005, 07:30 AM   #2
vls
Member
 
Registered: Jan 2005
Location: The grassy knoll
Distribution: Slackware,Debian
Posts: 192

Rep: Reputation: 31
grep will do what you need.

Are you sure you need to search the entire file system?

Did you create the file as a regular user (not root)? If so, the only place the file could be is in your $HOME or /tmp.

Try "grep -R -F 'string to find' $HOME/*"
"grep -R -F 'string to find' /*" if you have to search the whole system.
 
Old 12-16-2005, 07:41 AM   #3
neocookie
Member
 
Registered: Apr 2004
Location: Leeds, UK
Distribution: FC1, FC2, Debian
Posts: 308

Original Poster
Rep: Reputation: 30
Thanks. I'll give that a go.
 
Old 12-16-2005, 08:44 AM   #4
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
Never use grep yet but to find from "/" by naming the filename I always use

find / -name filename
 
Old 12-16-2005, 09:18 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by saikee
Never use grep yet but to find from "/" by naming the filename I always use

find / -name filename
OP wants to find a string IN a file....

The Gnome search tool has an option for searching in file contents.
 
Old 12-16-2005, 10:45 AM   #6
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
You are right I was caught out by the words
Quote:
whole linux file structure
 
Old 12-16-2005, 08:08 PM   #7
JimBass
Senior Member
 
Registered: Oct 2003
Location: New York City
Distribution: Debian Sid 2.6.32
Posts: 2,100

Rep: Reputation: 49
Code:
grep -e {string searched for} [locations to Search]
For example, if you created this file as a regular user, chances are good that it would be in home, as you don't have write permissions in many other places. If you wanted to find files with the word "drumstick" in them (title or contents), and you wanted to look in your home directory and all subdirectories, you would look for:

Code:
grep -e drumstick ~
If you knew drumstick was in the file name, then the find command with wildcards would be signifigantly faster. That command would look like:

Code:
find ~ -name *drumstick* -print
~ = /home/{username}, just a good shortcut. If you wanted to search the entire filesystem, then it becomes
Code:
find / -name *drumstick* -print
but you would need to do that as root, as it will spit some errors if you try to look in places where you don't have permissions to read.

Peace,
JimBass
 
  


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 command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
linux find to find files with multiple patterns subu_s Programming 6 12-15-2010 12:15 AM
linux 'find' to find text files subu_s Programming 2 12-02-2004 02:56 AM
Cant find files KillerCheeto Linux - Software 1 05-25-2004 12:55 AM
find out which files are in use saavik Linux - Networking 2 12-19-2002 03:42 AM


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