julianjensen
11/2/2015 - 8:53 PM

My .bash_aliases for handy recovery and sharing if anyone wants them. I have written and collected these over the last year or so.

My .bash_aliases for handy recovery and sharing if anyone wants them. I have written and collected these over the last year or so.

alias today='date +"%A, %B %-d, %Y"'
alias now='date +"%T"'
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias la='ls -FlA --human-readable'
alias ll='ls -Fl --human-readable'
alias t='clear;tail -50'
alias c='clear'
alias web='cd $METEL'

alias meminfo='free -m -l -t'

## get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='clear;ps auxf | sort -nr -k 4 | head -10'

## get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='clear;ps auxf | sort -nr -k 3 | head -10'

## Get server cpu info ##
alias cpuinfo='lscpu'

## get GPU ram on desktop / laptop##
alias gpumem='grep -i --color memory /var/log/Xorg.0.log'

## set some other defaults ##
alias df='df -H'
alias du='du -ch'

# ROT13-encode text. Works for decoding, too! ;)
alias rot13='tr a-zA-Z n-za-mN-ZA-M'

# top is atop, just like vi is vim
alias top='atop'

## Memcached server status  ##
alias mcdstats='/usr/local/bin/memcached-tool 127.0.0.1:11211 stats'
alias mcdshow='/usr/local/bin/memcached-tool 127.0.0.1:11211 display'

## quickly flush out memcached server ##
alias flushmcd='echo "flush_all" | nc 127.0.0.1 11211'

## redis flush
alias reflush='redis-cli flushall'

alias ps2='ps -ef | grep -v $$ | grep -i '
alias psg='ps -Helf | grep -v $$ | grep -i -e WCHAN -e '

# Sort by most recently modified
alias lt='ls -Falrt --human-readable'

alias filetree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

chr() {
  printf \\$(printf '%03o' $1)
  echo
}

ord() {
  printf '%d' "'$1"
  echo
}

hf() {
  history | grep -i "$@" | grep -v "hf $@"
}

alias lls="ls -Fla $1 $2 $3 $4 $5  | awk '{ print; x=x+\$5 } END { print \"total bytes = \",x }'"

alias machine="echo you are logged in to `uname -a | cut -f2 -d' '`"
alias connections='sudo lsof -n -P -i +c 15'

alias rl='. ~/.bash_aliases'

alias .p="pushd"
alias p.="popd"

function txt() { grep -rHn --exclude=*.map --exclude=*.min.* $@ *; }
function itxt() { grep -rHin --exclude=*.map --exclude=*.min.* $@ *; }

alias bigfiles="find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk '{ if ( \$1 > 5000) print \$0 }'"
alias verybigfiles="find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk '{ if ( \$1 > 500000) print \$0 }'"

function json() { cat “$@” | /usr/bin/python -m json.tool ;}

# List directories by size, largest on top
function dus () {
du --max-depth=0 -k * | sort -nr | awk '{ if($1>=1024*1024) {size=$1/1024/1024; unit="G"} else if($1>=1024) {size=$1/1024; unit="M"} else {size=$1; unit="K"}; if(size<10) format="%.1f%s"; else format="%.0f%s"; res=sprintf(format,size,unit); printf "%-8s %s\n",res,$2 }'
}

# File size
alias fs="stat -f \"%z bytes\""

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

export HISTCONTROL=ignoredups
export HISTIGNORE="&:ls:[bf]g:clear:c:[ ]*:exit:pwd:cd"

# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en1"
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"
myip() {
    curl http://ipecho.net/plain;
    echo;
}

alias back='cd $OLDPWD'

up()
{
    dir=""
    if [ -z "$1" ]; then
        dir=..
    elif [[ $1 =~ ^[0-9]+$ ]]; then
        x=0
        while [ $x -lt ${1:-1} ]; do
            dir=${dir}../
            x=$(($x+1))
        done
    else
        dir=${PWD%/$1/*}/$1
    fi
    cd "$dir";
}

alias whois="whois -h whois-servers.net"
# alias whois='whois -H'

# View HTTP traffic
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""

# Canonical hex dump; some systems have this symlinked
type -t hd > /dev/null || alias hd="hexdump -C"


# Kill all the tabs in Chrome to free up memory
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"

# Case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob

# Append to the Bash history file, rather than overwriting it
shopt -s histappend

# Autocorrect typos in path names when using `cd`
shopt -s cdspell

shopt -s histverify

# Enable some Bash 4 features when possible:
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux`
# * Recursive globbing, e.g. `echo **/*.txt`
for option in autocd globstar; do
	shopt -s "$option" 2> /dev/null
done

alias wallpaper="wallch --start >/dev/null 2>&1 &"

# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh