What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands tagged apache from sorted by
Terminal - Commands tagged apache - 26 results
sort -s -b -t' ' -k 4.9,4.12n -k 4.5,4.7M -k 4.2,4.3n -k 4.14,4.15n -k 4.17,4.18n -k 4.20,4.21n access.log*
2015-07-16 00:22:03
User: sesom42
Functions: sort
Tags: sort log apache

Sort Apache access logs by date and time using sort key field feature

openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "/C=BR/ST=State/L=City/O=Company Inc./OU=IT/CN=domain.com"
tail -f access_log | awk '{print $1 , $12}'
2014-12-24 14:15:52
User: tyzbit
Functions: awk tail

Use this command to watch apache access logs in real time to see what pages are getting hit.

cat /etc/httpd/logs/access.log | awk '{ print $6}' | sed -e 's/\[//' | awk -F'/' '{print $1}' | sort | uniq -c
2014-10-13 13:39:53
User: suyashjain
Functions: awk cat sed sort uniq

The command will read the apache log file and fetch the virtual host requested and the number of requests.

/usr/bin/tail -fn0 /path/to/apache_error.log | while read line; do /usr/local/bin/growlnotify --title "Apache Notice" --message "$line"; done &
2013-01-22 05:25:41
User: jhyland87
Functions: read

Simply add this to whatever apache startup script you have, or if you are on a MAC, create a new automator application. This will show a pretty growl notification whenever theres a new Apache error log entry. Useful for local development

CustomLog "|nc -u IP PORT "<134>%{%b %d %X}t %h %l %u %t \"%r\"%>s %b \"%{Referer}i\" \"%{User-agent}i\""
2012-12-26 09:32:52
User: flojb
Tags: apache nc syslog

Send apache log to syslog-ng server without change configuration of syslog.

Just add in httpd.conf or vhost conf.

openssl rsa -in /path/to/originalkeywithpass.key -out /path/to/newkeywithnopass.key
2012-09-16 19:31:38
User: drerik

Strip a password from a openssl key to use with apache httpd server

apache2 -l
httpd -M
2012-05-27 12:04:17
User: rockon

Easiest way to check which modules are loaded in apache.

ps h --ppid $(cat /var/run/apache2.pid) | awk '{print"-p " $1}' | xargs sudo strace
2012-03-21 01:59:41
Functions: awk cat ps sudo xargs

Like the original version except it does not include the parent apache process or the grep process and adds "sudo" so it can be run by user.

sudo chown -R nobody:admin /Applications/XAMPP/xamppfiles/htdocs/
awk -F\" '/^DocumentRoot/{print $2}' $(httpd -V | awk -F\" '/\.conf/{print $2}')
httpd -V | grep -i SERVER_CONFIG_FILE | cut -f2 -d'"' | xargs grep -i '^DocumentRoot' | cut -f2 -d'"'
2011-08-13 20:45:05
User: dcpesses
Functions: cut grep

Grabs the Apache config file (yielded from httpd) and returns the path specified as DocumentRoot.

top -p `pidof apache2 | awk '{gsub(/[ ]/,",");print}'`
pidof httpd | sed 's/ / -p /g' | xargs strace -fp
( apache2ctl -t && service apache2 restart || (l=$(apache2ctl -t 2>&1|head -n1|sed 's/.*line\s\([0-9]*\).*/\1/'); vim +$l $(locate apache2.conf | head -n1)))
2010-11-26 18:12:08
User: cicatriz
Functions: head locate sed vim

Checks the apache configuration syntax, if is OK then restart the service otherwise opens the configuration file with VIM on the line where the configuration fails.

goaccess -f /var/log/apache2/access.log -s -b
2010-10-25 20:03:18
User: allinurl

GoAccess is an open source real-time Apache web log analyzer and interactive viewer that runs in a terminal in *nix systems. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly. http://goaccess.prosoftcorp.com/

awk '$1~/^DocumentRoot/{print $2}' /etc/apache2/sites-available/default
grep -i '^DocumentRoot' /etc/httpd/conf/httpd.conf | cut -f2 -d'"'
tail -n2000 /var/www/domains/*/*/logs/access_log | awk '{print $1}' | sort | uniq -c | sort -n | awk '{ if ($1 > 20)print $1,$2}'
sudo awk '($9 ~ /404/)' /var/log/httpd/www.domain-access_log | awk '{print $2,$9,$7,$11}' | sort | uniq -c
2010-04-09 10:31:50
User: ninjasys
Functions: awk sort sudo uniq
Tags: log error apache

This command will return a full list of Error 404 pages in the given access log. The following variables have been given to awk

Hostname ($2), ERROR Code ($9), Missing Item ($7), Referrer ($11)

You can then send this into a file (>> /path/to/file), which you can open with OpenOffice as a CSV

zcat access_log.*.gz | awk '{print $7}' | sort | uniq -c | sort -n | tail -n 20
sudo strace -pXXXX -e trace=file
ab -n 9000 -c 900 localhost:8080/index.php
2009-08-07 07:19:40
User: amaymon

-n 9000 : Number of requests to perform for the benchmarking session

-c 900 : Number of multiple requests to perform at a time

/usr/sbin/apache2ctl -S 2>&1 | perl -ne 'm@.*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root =~ s/^\s+//; print "\t$root\n" };'
2009-07-21 10:51:30
User: lingo
Functions: perl

Lists virtualhosts currently enabled for apache2, showing the ServerName:port, conf file and DocumentRoot