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
Solved

find files with specific content on linux system

Posted on 2011-03-18
7
318 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
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Utilizing an array to gracefully append to a list of EmailAddresses
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
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…

840 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