Bash - Bourne Again SHell

First, some general BASH links:

Bash Tricks

This was a short presentation intended to demonstrate quick little time-savers. It also covered basic job control.

Bash uses Emacs editing keys. These are beyond the scope of this quick-reference, but two that will be useful even if you don't use Emacs are:

Ctrl-U- Cut (from from cursor to beginning of line)
Ctrl-Y- Paste (At Cursor)

As well as being used as cut & paste, these allow you to hide the command you're currently typing, enter another, and then continue.

For instance, if you're typing a long command cat foo | sort | uniq | grep ... and you forget the syntax of grep. You press Ctrl-U to remove the current command and type man grep . When you find the switch you're looking for you exit the man page, press Ctrl-Y , and continue your command.

This can also be accomplished by switching to another virtual console, another window in your terminal (xterm, konsole, etc) or by using screen.


It is often handy to create a new command, or modify an existing one, to perform a common task with less keystrokes. One example would be setting ls to perform ls -l by default. The command to do this is alias ls="ls -l" .

A full list of aliases can be displayed by typing alias, or a specific alias can be displayed by specifying the command such as alias ls .

If you want to show the alias for every command on a command-line (a time-saver when many commands are used together) type Ctrl-Alt-e which will replace the commands with their full expanded versions.

Job Control

Bash offers some basic commands for controlling the active program and switching between programs.

Start a program, man bash for instance. Press Ctrl-Z and you will be returned to the prompt. If you type jobs you will get a list of jobs this bash window is controlling. For example:

[1]+  Stopped                 man bash

The program is suspended. It's not running, but you can continue it at any time by using fg to bring it to the foreground (as when you ran it initially) or bg to put it into the background.

Interactive programs ( man for instance) won't continue to run in the background, they'll be suspended as soon as they wait for user input.

If you have multiple jobs, use the job number (as reported by jobs, not by ps) to control it, such as bg 3 to put job three into the background.

If you need to kill any of these jobs, use a percent sign and the job number, otherwise you'll end up killing the wrong job. For example, kill %1 will kill the first job in bash's jobs list, kill 1 will kill process 1, or init, which will crash your system.

To put a job directly into the background, use an ampersand at the end of the command-line. The job will run but you will be returned to a prompt and be able to run more commands. For example locate -u & will update the locate ? database without you having to wait for it. (This is good to put into cron ? and run periodically.)

Tab completion

I tried using Zsh for a little while because I loved some of its tab-completion features, but it seemed a little slow and poky to me, so I came back to bash, and then I found bash-completion. What a wonderful little addition to bash.

It allows you to do things like type in: ssh <tab> and this will list the entries in your ~/.ssh/known_hosts file.

Or you can type in: ls - <tab>

and this will list all the available options for ls.

I won't go any further with examples. I suggest you install it and give it a try.

Jimson ?

Environment Variables

Here's a list of handy things you can export from your ~/.bashrc to customize your environment to the way you want to work: