Carisenda

this space left intentionally blank

Use(ful|less) Unix

Useful to me anyway, at least once, maybe even more!

This is an ever increasing, unsorted, poorly documented list of some Unix one-liners I use or have used (I kept them on my wiki but I'm moving them here, slowly) which may or may not be useful to you (they were useful for me).

Grab the referrers from yesterday in an Apache access log:
awk -v date="`date -d yesterday '+%d/%b/%Y'`" -F\" '($1 ~ date && $2 ~ /GET \/ /){ print $4}' access.log | awk -F\/ '(/http/){print $1"//"$3"/"}' | sort | uniq -c | sort -nr

Top 10 CPU hogs (Magento!):
ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Where have I been logging in from?
last -20 -i $USER | awk {'print $3'} | perl -ne'/^\d/ && print' | sort | uniq -c | sort -nr

Find 'needle' in the source of website 'http://haystack':
perl -MLWP::Simple -e "getprint('http://haystack/')||die" | grep needle

Mirror a website locally:
wget --mirror -w 2 -p --convert-links -P -nH /local/path/to http://www.yourdomain.com

Email me when job is done:
./big_jobs.pl && echo | mailx -s "Big Jobs completed" mekquake@abc.mil

Get the HTTP Headers of a site:
curl -I http://www.banjax.com/

* * *

See Also: System Administrator Interview Cheat Sheet