?
Solved

Please decipher this Linux command

Posted on 2004-03-27
4
Medium Priority
?
271 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 2000 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Fine Tune your automatic Updates for Ubuntu / Debian
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…
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.
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

801 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