Solved

find files with specific content on linux system

Posted on 2011-03-18
7
316 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

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)

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now