Solved

Please decipher this Linux command

Posted on 2004-03-27
4
268 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
[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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Fine Tune your automatic Updates for Ubuntu / Debian
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.
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.

730 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