Solved

Please decipher this Linux command

Posted on 2004-03-27
4
267 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Postfix issues with spam/auth attempts under NAT 9 110
Install Predefined Certificate on Ubunto 4 48
awk file 6 77
error log using ftp 7 56
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

791 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