Just a quick post to write up an bash alias I just created to list the sites enabled on a server and each sites location.
I often need to look up the list of sites enabled on a web server and also the document roots of each of these sites. In the past this meant loading the Apache configuration file into emacs or vim and searching for the site I was looking for. Today I decided to create an alias for this task. Here is the original combination of grep commands.
grep ''^ServerName" -A 3 /etc/apache2/sites-available/default | \ grep "^ServerName\|^DocumentRoot\|^--"
Searches the file for all lines that begin with ServerName at the beginning of the line.
Prints the 3 lines after the match.
3. grep “^ServerName\|^DocumentRoot\|^–”’
Prints only the lines that we are interested (ie lines that begin with ServerName or DocumentRoot or –)
The “\|” in the second grep command separates the regex with an “or” statement.
Choose a name for the command, in my case, show-sites
Add the alias to the .bashrc or .bash_alias file in your home directory
alias show-sites='grep "^ServerName" -A 3 /etc/apache2/sites-available/default | \ grep "^ServerName\|^DocumentRoot\|^--"'
Reload Your Bash Configuration
Show All Current Aliases
Type alias at the command line to view all of the currently defined aliases.