Solved

Please decipher this Linux command

Posted on 2004-03-27
4
261 Views
Last Modified: 2013-12-15
I've asked someone to create a search command to find a string in my RH Linux box. The following is supposed to be on one line:

find /usr/local/psa/home/vhosts -type f -iname \*\.php\* | awk '{printf("grep -Hi DT_formmail \"%s\"\n", $0)}' | sh | awk -v FS=":" '{print $1}' 2>/dev/null | sort -u

Please tell me EXACTLY what the above command is supposed to do in simple English and if the command looks valid. I need to verify his
work. Thanks.
0
Comment
Question by:topwiz
  • 3
4 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 10694245
You are searching the directory (and all subdirs) /usr/local/psa/home/vhost for files that have an .php extension (and you are searching case insensitive, so you will also find test.PHP for example). You are then sending the file names to your awk command that creates a command line for grep by adding the file names. This is then piped (and therefore executed) by a shell. The output of this grep command is then split up using ':' as delimiter, and the first element ($1) is printed. This will create a list of all .php file names that contain the string DT_formmmail. This list is then sorted.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10694258
I probably would modify it like this:

find /usr/local/psa/home/vhosts -type f -iname \*\.php\* | xargs grep -lHi DT_formmail  | sort -u
0
 

Author Comment

by:topwiz
ID: 10694285
khkremer, I will accept your excellent answer. Yes, that is what I asked him to do; create a list of all .php (case insensitive) file names that contain the string DT_formmmail. How do I modify the command to look for "DT_formmmail" in case insensitive?

BTW in simple English, why do you say your modified command is better? I will give bonus points if you can assist further, thanks!

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10694316
I did not say it's better :-) It's shorter and avoids two calls two awk and one explicit shell (which you have to do for the grep anyways).

The grep for DT_frommail is already case insensitive (that's done by the "i" parameter to grep).
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

13 Experts available now in Live!

Get 1:1 Help Now