Adding functions into your .bashrc file makes shortcuts available in your shell session by just typing the name of the function. These are just a few of the ones I have in my own .bashrc file, some are silly, some are useful 🙂
# bu - A quick backup function bu () { cp $1 ~/Backups/${1}-`date +%Y%m%d%H%M`.backup ; } # hs - History Search hs() { history | grep ${1} | uniq --skip-fields=1 | sort -biz | uniq --skip-fields=2 } # stock - Stock information search. stock () { lynx -dump “http://www.google.com/finance?client=ob&q=${1}” \ | sed ‘s/.*’]'//’ | perl -00ne “print if /Watch this stock/i” \ | sed ‘s/Watch this stock//’ | sed ‘s/Disclaimer//’ \ | sed ‘/^$/d’ | sed ‘s/Currency in USD//’ } # smallurl - create a shorter url link. smallurl () { lynx --dump http://api.fwd4.me/?url=${1} } # grepp - Imitate grep -p functions from Tru64 OS. grepp () { perl -00ne "print if /$1/i" < $2 } # clock - A stupid clock function :) clock () { while true;do clear;echo "===========";date +"%r";echo "===========";sleep 1;done } # dirsize - Directory contents sorted by size. dirsize () { du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \ egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list egrep '^ *[0-9.]*M' /tmp/list egrep '^ *[0-9.]*G' /tmp/list rm /tmp/list } # extract - Extract most types of compressed files easily # I think I found this one on the archlinux forums extract () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvf $1 ;; *.tar.gz) tar xvf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xvf $1 ;; *.tgz) tar xvf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted via >extract<" ;; esac else echo "'$1' is not a valid file" fi } ############################################################# ########### ENCRYPTION / DECRYPTION FUNCTIONS ############### ############################################################# dc () { # Passphrase decryption program # Created by Crouse 10-20-2009 # Decrypts symetrically encrypted file to std out. gpg --no-options --output .tempdc.txt "$1" cat .tempdc.txt | less; rm -f .tempdc.txt } ec () { # Passphrase encryption program # Created by Crouse 01-13-2006 # Reads input from text editor and encrypts to screen. clear echo " " echo "**************************************************"; echo "* Passphrase Encryption Program *"; echo "**************************************************"; echo ""; which $EDITOR &>/dev/null if [ $? != "0" ]; then echo "It appears that you do not have a text editor set in your .bashrc file."; echo "What editor would you like to use ? " ; read EDITOR ; echo ""; fi echo "Enter the name/comment for this message :" read comment $EDITOR passphraseencryption gpg --armor --comment "$comment" --no-options --output \ passphraseencryption.gpg --symmetric passphraseencryption shred -u passphraseencryption ; clear echo "Outputting passphrase encrypted message"; echo "" ; echo "" ; cat passphraseencryption.gpg ; echo "" ; echo "" ; shred -u passphraseencryption.gpg ; read -p "Hit enter to exit" temp; clear } # Passhprase edit encrypted file program # Created by Crouse 11-02-2009 # Allow editing of symetrically encrypted files. eedit () { gpg --force-mdc --no-options --output .tempeec $1 emacs .tempeec #vi .tempeec gpg --armor --force-mdc --no-options --output $1 --symmetric .tempeec shred -u .tempeec~ ;shred -u .tempeec ; clear #shred -u .tempeec } enc () { gpg --armor --no-options --output tempenc.txt --symmetric "$1" mv tempenc.txt "$1" } dec () { gpg $1 } encnotes () { echo "dc = decrpyt to screen" echo "ec = encrypt to screen" echo "enc = encrypt file to disk - overwrite existing" echo "dec = decrypt file to disk - creates new file" }