[Chugalug] Command Line Foo v2.0

Jon Stanford jbirdvegas at aokp.co
Sat Aug 10 15:48:46 UTC 2013

So I've been beefing up my ~/.bashrc with some useful, and some not so useful CLI magic.  I thought I would share some of my fav functions... and offer a beat that style discussion ;)

One thing I'm working on is using the takepic to capture an image of anyone who opens the terminal and eventually everytime the computer turns on. The problem is each time it overwrite the previous pic, so I can't keep a directory with all the pics using the date as the filename. :(

Here are my fav functions.

# Take webcam pics
#usage: takepic 4 #takes four pictures
takepic() {
   if [ -z "$1" ]; then
     echo "Taking one picture"
     mplayer -vo png -frames 1 tv://
     echo "Taking $1 pictures"
     mplayer -vo png -frames "$1" tv://

#show a pretty figlet clock (blocks term)
clock() {
    while [ 1 ]; do
        date +%r | figlet
        sleep 1

#search wikipedia for a term
wiki() {
    if [ -z "$1" ]; then
        echo -e "You must supply a query\nie: wiki Snoop\ Dogg"
        dig +short txt "$1".wp.dg.cx

#get my external IP
myip() {
     curl ifconfig.me

#show time in top right of terminal (persistant, constantly updated and doesn't block term)
showtime() {
    while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &

#get all the strings from RAM **may contain private info like passwords**
showram() {
    sudo strings /dev/mem

#make a graphical representation of the underlying directories from current location in file tree
graphtree() {
    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

#free memory that is no longer being used
freemem() {
    free && sync && echo 3 > /proc/sys/vm/drop_caches && free

#shows files that changed across the system in a 10 second period (useful for auditing software when you need
to know what an app is actually doing to your box)
diffsystem() {
    diff <(lsof -p 1234) <(sleep 10; lsof -p 1234)

#binary clock (nerd fun, blocks term)
binclock() {
    watch -n 1 'echo "obase=2;`date +%s`" | bc'

#grab unread gmail messages (title, sender and body) **you must change $USERNAME:$PASS... odviously** 
dumpgmail() {
    curl -u $USERNAME:$PASS --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*<name>(.*)<\/name>.*<body>(.*)<\/body>.*$/$2 - $1/' > temp.html;
    w3m -dump temp.html;
    rm temp.html

#find all dirty mem pages (useful if your wondering the potential loss of improper shutdowns)
dirtydata() {
    grep ^Dirty /proc/meminfo

#fake hacking (looks cool but does nothing... like hacker screens in the movies)
hexhack() {
    cat /dev/urandom | hexdump -C | grep "ca fe"

#find most recently used files (60min window)
findrecentfiles() {
    sudo find / -mmin 60 -type f

#shows my current city, state and country (based on your IP)
mylocal() {
    lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\'

#listen to BBC radio (blocks term)
bbcradio() {
    local s PS3="Select a station: ";select s in 1 1x 2 3 4 5 6 7 "Asian Network an" "Nations & Local lcl";do break;done;s=($s);mplayer -playlist "http://www.bbc.co.uk/radio/listen/live/r"${s[@]: -1}".asx";

#grab a fresh excuse for... well anything :)
excuse() {
    telnet towel.blinkenlights.nl 666

#constantly watch udev for configuration changes (useful when debugging connections to the computer, ex USB, Power, CD-ROM, ...)
watchudev() {
    udevadm monitor

More information about the Chugalug mailing list