LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-22-2008, 09:00 AM   #1
zodehala
Member
 
Registered: Nov 2008
Posts: 53

Rep: Reputation: 15
search text in any files


how can i search any text in any file for example i wannto search "zode" text in all files in /var/www/html/ ?
 
Old 11-22-2008, 09:10 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
If all you want is to see if it exists, then try this:

grep zode /var/www/html/*

If you need to know which file the text appeared in, then you need to make a small loop which iterates thru the file list, and prints the file name whenever grep has a positive result.

I recommend starting with the Bash Guide for Beginners by Machtelt Garrels---free at http://tldp.org
 
Old 11-22-2008, 09:10 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
In a terminal:
Code:
grep zode /var/www/html/*
man grep for more information.
 
Old 11-22-2008, 09:12 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by pixellany View Post
If you need to know which file the text appeared in, then you need to make a small loop which iterates thru the file list, and prints the file name whenever grep has a positive result.
If grep is given a wildcard as part of the list of files, I believe it prints the name of the file before each match. You can also use the -H flag in grep to force this behaviour if it's not done by default.
 
Old 11-22-2008, 09:58 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
In addition, to extend the search to the files inside subdirectories (if any) you can try the find command in conjunction with grep (using xargs):
Code:
find /var/www/html -type f -print0 | xargs grep zode
 
Old 11-22-2008, 10:27 AM   #6
zodehala
Member
 
Registered: Nov 2008
Posts: 53

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
In addition, to extend the search to the files inside subdirectories (if any) you can try the find command in conjunction with grep (using xargs):
Code:
find /var/www/html -type f -print0 | xargs grep zode
Code:
find /var/ -type f -print0 | xargs grep Announcements
Code:
xargs: argument line too long
 
Old 11-22-2008, 10:27 AM   #7
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 69
grep has a -r flag for recursion:
Code:
grep -r zode /var/www/html
 
  


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
Help with BASH to search text files on disk purveshk Linux - Newbie 5 06-23-2015 03:31 PM
Search for text inside files alaios Linux - Newbie 7 03-12-2006 10:20 AM
Perl: Search and replace directories within text files Erhnam Programming 2 03-07-2006 05:07 AM
Search text in files remotely anjanesh Red Hat 2 08-15-2005 10:03 AM
Search all text files? nextekcarl Linux - General 4 10-20-2004 01:18 PM


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