optimize your shell environment

Here are some random improvements to the shell (bash) environment that I like to use on the servers I manage. You can simply add the code snippets to your .profile file.

how to show more information in process list

You can improve the information that the ps command shows by default by setting the environment variable PS_FORMAT:

export PS_FORMAT='user,pid,ppid,tty,pcpu,pmem,stat,thcount,start,time,cmd'

prevent accidental overwrite by output redirect

It is easy to accidentially overwrite a file by redirecting the output of a command into a file that already exists. If you add

set -o noclobber

to your bash profile, you safe yourself from a lot of trouble. if you want to overwrite a file intentionally, you can use >| instead of a simple >. Here's an example:

$ ls > tmpfile
$ ls > tmpfile
bash: tmpfile: cannot overwrite existing file
$ ls >| tmpfile

ignore some files or directories for tab completion

Some directories, like e.g. .svn should not be taken into account for tab completion of file names. Put them in a colon separated list in the environment variable FIGNORE:

export FIGNORE='.svn:~'

control how bash handles the history

Tell bash to save ignore dulicates in saving the history.

export HISTCONTROL=ignoredups

You can set HISTIGNORE to a colon separated list of commands that shall not be saved in the history.

export HISTIGNORE="ls:exit:bg:fg"

Make history immediately available from all bash instances:

shopt -s histappend