Setting Up Raspbian Bash Shortcuts

As I've written before I'm a big fan of bash shortcuts, aka aliases (I also wrote about it a second time). When I got a new [Raspberry Pi](/tags/raspberry-pi) I really missed using them. So I learned how to set them up.

It’s Pretty Simple

The docs explain pretty clearly how to do this, and how the existing .bashrc is set up. You can see these hidden files by running ls -a on the Raspbian command line:

pi@raspberrypi:~ $ pwd
/home/pi

pi@raspberrypi:~ $ ls
Desktop Documents Downloads MagPi Music Pictures Public Templates Videos

pi@raspberrypi:~ $ ls -a
. .bash_aliases .bash_logout .cache Desktop Downloads .local Music .pki Public .thumbnails .vnc .xsession-errors
.. .bash_history .bashrc .config Documents .gnupg MagPi Pictures .profile Templates Videos .Xauthority .xsession-errors.old

On a fresh Raspbian install, this .bash_aliases file won’t be there, so you need to create it:

pi@raspberrypi:~ $ touch .bash_aliases

Then open the file:

pi@raspberrypi:~ $ nano .bash_aliases

Then add your commands. In my case, I wanted to start & stop my remote desktop server more easily, and create a shortcut to take a photo:

alias vncstart='vncserver :1 -geometry 1280x720 -depth 24'
alias vncstop='vncserver -kill :1'
alias cam='raspistill -o'

Press ctrl + x to begin exiting Nano, y to save, and Enter (or Return) to save it to the same filename.

Once back on the command line, run source .bashrc to bring the new aliases into effect.

Voila!