A few helpful Bash settings and aliases

I’m constantly trying to get my hands off the mouse and onto the keyboard so I’ve been looking for tweaks and tricks to help me to do what I need to do with fewer mouse clicks and keystrokes. I’ve been using a mouse regularly since using an Amiga 1200, so 20 years habit is proving a bit tricky to break.

Anyway, here’s some things and what they do. I prefer to put everything in ~/.bash_aliases rather than using .bashrc for anything. I’m not at all sure if this is a good thing or not. It works for me though.

# Create parent dirs if they don't exist
alias mkdir="mkdir -p"

# Easy access to Apache logs
alias he='tail -n 100 -f /var/log/apache2/error.log'
alias ha='tail -n 100 -f /var/log/apache2/access.log'
alias hr='tail -n 100 -f /var/log/apache2/rewrite.log'

# Restart Apache
alias apr='sudo service apache2 restart'

# Run log files through tail
alias t100='tail -n 100 -f'

# Ubuntu updates, including a fix to avoid dl.google.com being painfully slow
alias update='sudo apt-get -o Acquire::http::Pipeline-Depth=0 update && \
              sudo apt-fast upgrade'

# Shows list of previous commands to be rerun with !{command-number}
alias h='history'

# Speaks for itself
alias svi='sudo vi'

# Ascend directories easily
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."

# Tidy a terminal so I don't keep wondering if I was halfway through something
alias c="cd; clear"

# SVN
alias sc="svn ci -m"
alias ss="svn status"
alias sup="svn up" 

# Git
alias gs="git status"
alias gp="git push"
alias gc="git commit -a -m"
alias ga="git add"

# Shortcuts to projects example
alias sand='cd /var/www/sandbox'  #webroot
alias sands='cd /usr/local/src/sandbox/trunk' #source trunk
alias sandb='cd /usr/local/src/sandbox/branch/1,0.1' #source live branch
alias sandl='tail -n100 -f  /var/www/sandbox/logs/sandbox.log' #run log through tail

# SSH example
# I use a config file for all connections with key access, but 
# don't want to type 'ssh {connection}' everytime
alias sandbox='ssh sandbox.com'

# Run root commands without full path
export PATH=$PATH:/sbin

# System control
alias halt="sudo halt"
alias reboot="sudo reboot"

# BASH commands
# Run BASH in vi mode
set -o vi

# Try to correct typos when using 'cd'
shopt -s cdspell

# Try to correct typos when doing anything else on directories
shopt -s dirspell

$ Type a directory name to cd into it
shopt -s autocd

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>