The Bash Shell

I've always used the bash shell as my preferred shell for doing command line stuff (CLI). To change to this shell on various systems such as FreeBSD, SunOS, Linux etc. use the command chsh to change the shell to shell or any other shell such ash zsh, sh, csh etc.

[martin@odin linux]$ chsh
Changing shell for martin.
Password:
New shell [/bin/bash]:
[martin@odin linux]$

Shell shortcuts

These shortcuts makes it a little bit easier to move around the shell.

Line-editing:
^B    moves back a single character.
^F    moves forward a single character.
^A    moves to the beginning of the line.
^E    moves to the end of the line.
^H    and DEL delete the previous character.
^D    deletes the current character.
^K    deletes from current position to the end of line.
^L,^R redraws line in case it gets trashed.
^U    deletes the entire line.
^W    deletes from the current word to the end of line.

History:
^P    moves back through history.
^N    moves forward through history.

Customising your bash shell

Customisations is done in the file ~/.bashrc and I have a few of those.

History Size

History size on the bash command line is by default 1000 lines and saved in ~/.bash_history. I prefer 10000, so I have the following setting.

export HISTSIZE=10000

Ignoring commands written to history

For either security reasons it may have some advantages to to have some command line history kept out of the history file.

export HISTIGNORE="ls:[fb]g:exit:pwd"

This one ignores all commands starting with ls, fg, bg, exit, or pwd.

Customising the command-line look

The commandline may typically look like this when you enter a terminal.

[martin@odin ~]$
#or like this
-bash-2.05b$

Where martin is the username, odin is the name of the server and ~ is the path (home directory). The setting is done using the following setting in ~/.bashrc. Notice that no set or export is used.

PS1='[\u@\h \W]\$ '
#or the default:
PS1='\s-\v\$ '

The default settings can be overridden by setting the PS1 environment variable. You may want to have the time stamp written and/or the full directory path that you are in. This can be done using the following setting in ~/.bashrc.

See the PROMPTING part in the bash manual (man bash).

ls customisations

The list function ls is per default customised on many systems and a few of those are:

# Using ll to list files prettyly
alias ll='ls -l --color=tty' 2>/dev/null
# Show only dot (.) files/directories
alias l.='ls -d .* --color=tty' 2>/dev/null
# Show in color-mode
alias ls='ls --color=tty' 2>/dev/null
# Show only directories
alias lsd='ls -d */' 2>/dev/null

Other customisations

I have a few weird, but practicle customisations.

XMMS commandline options:

alias x='xmms -e' # x myfile.mp3 adds file
alias xs='xmms -u' #xmms stop
alias xp='xmms -p' #xmms play
alias xf='xmms -f' #xmms forward
alias xr='xmms -r' #xmms rewind

Various practical aliases

alias gvim='gvim -geometry 100x53' # open vim in specific size
alias vin='vim --noplugin' # open vim without plugins
alias dvips='dvips -t a4' # always print use dvips with a4-option
alias oo=openoffice.org-2.0 # abbreviation for openoffice
alias s=smbstatus # show samba status
# make dvips do high quality output with dvipshq
alias dvipshq='dvips -j0 -Ppdf -Pdownload35 -G0\
               -t A4 -D 1200 -Z -mode ljfzzz'
alias dvipdf='dvipdf -sPAPERSIZE=a4' # force a4 size for dvipdf command

Valid XHTML 1.0 Transitional