Solved

find files with specific content on linux system

Posted on 2011-03-18
7
322 Views
Last Modified: 2012-05-11
hi

i need a bash command to find files

1) all .php files in a directory and all subdirectories containing a specific search string
2) all .php files in a directory and all subdirectories  belonging to a specific user and group
3)  all .php files in a directory and all subdirectories containing a specific search string and owned by a specific user and group

Thanks
0
Comment
Question by:netslt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35166825
find /directory -type f -name "*.php" | xargs grep -l "search string"

find /directory -type f -name "*.php" -user userid -group groupid

find /directory -type f -name "*.php" -user userid -group groupid  | xargs grep -l "search string"

0
 

Author Comment

by:netslt
ID: 35166885
great!

 just another thing that came to my mind: would it also be possible to search for two or more strings, eg "containing string 1 OR string 2 OR string 3"

and would it be possible to output the line from the file where the string was found?

thanks!
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35166900
find /directory -type f -name "*.php" | xargs egrep -l "string1|string2|string3"

0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 35166949
>> output the line <<

find /directory -type f -name "*.php" | xargs egrep "string1|string2|string3" /dev/null

just without "-l"
/dev/null at the end is to display the filename even if only one file is found. No "|" or ">" in front of it!

wmp

0
 

Author Closing Comment

by:netslt
ID: 35167065
grossartig wie immer - vielen dank!
0
 
LVL 3

Expert Comment

by:Alberto Cortes
ID: 35167108
Solution:

find /directory/path -name "*string*.php" -print 2> /dev/null
find /directory/path -name "*string*.php" -group <group_name> -user <user_name> -print 2> /dev/null
find /directory/path -group <group_name> -user <user_name> -print 2>/dev/null | xargs grep "string"
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35168563
Danke fuer die Punkte und viele Gruesse in die schoene Schweiz!

wmp
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question