Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged apache from sorted by
Terminal - Commands tagged apache - 23 results
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
0

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
0

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
1

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
2

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
1

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
2

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
1

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
3

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
1

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
1

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
10

-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
4

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

apache2 -t -D DUMP_MODULES
2009-02-16 17:30:20
User: ElAlecs
Tags: apache httpd
5

This let you know which modules has loaded the Apache server, very useful to know if the mod_rewrite is ready to use.