Solved

Please decipher this Linux command

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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

688 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