By Paul Tero CHAPTER 8
regular expression. Regular expressions are a huge topic in their own right.
In the command below, the s/ /\ /g will replace all spaces with a slash
followed by a space:
$ find / -type f ( -name *conf -o -name *include ) 2>/dev/null | sed
's/ /\ /g'
/var/spool/postfix/etc/resolv.conf
/var/some\ file\ with\ spaces.conf
/var/www/vhosts/myserv.com/conf/last_httpd.include...
Now you can use a backtick to embed the results of that find command
into a grep command. Using ` is different than | as it actually helps to build
a command, rather than just manipulating its input. The -H option to grep
tells it so show file names as well. So, now we will look for any reference to
“smashingmagazine” in any conf files.
$ grep -H smashingmagazine find / -type f \( -name \*conf -o -name \*in- clude \) 2> /dev/null | sed 's/ /\\ /g'
/var/www/vhosts/smashingmagazine.com/conf/last_httpd.include: ServerName
"smashingmagazine.com"...
This may take a few seconds to run. It is finding every conf file on
the server and searching through all of them for “smashingmagazine”. It
may reveal the DocumentRoot directly. If not, it will at least reveal the file
where the ServerName or VirtualHost is defined. You can then use grep or
less to look through that file for the DocumentRoot.
You can also use the xargs command to do the same thing. It also
allows the output from one command to be embedded into another:
$ find / -type f ( -name *conf -o -name *include ) 2> /dev/null | sed
's/ /\ /g' | xargs grep -H smashingmagazine
/var/www/vhosts/smashingmagazine.com/conf/last_httpd.include: ServerName
"smashingmagazine.com"...
$ grep DocumentRoot /var/www/vhosts/smashingmagazine.com/conf/last_httpd.include
DocumentRoot "/var/www/vhosts/smashingmagazine.com/httpdocs"