Pejman Moghadam / General

Bash Rules

Public domain

Environment Variables

these variables can be saved in ~/.bash_profile or ~/.bashrc

decide which command lines should not be saved on the history list

HISTIGNORE="&:[ ]*:ls:exit"

list of search paths for commands:


list of directories used as search path for the "cd" command


list of directories used as search path for the "man" command


Colorful prompt

# Bright
PS1="\n\[\e[1;31m\]\t - \d\n\[\e[1;32m\]\u@\H:\[\e[1;36m\]\w \\$ \[\e[0m\]"
# Dark 
PS1="\n\[\e[0;31m\]\@ - \d\n\[\e[0;33m\]\u@\H:\[\e[0;32m\]\w\\$ \[\e[0m\]"

Login timeout seconds


Current process PID

echo $$

The number of seconds the script has been running


Command Substitution


kill -TERM `cat /var/run/`


kill -TERM $(cat /var/run/

Special shorcuts

run last command


reuse last parameter (you can use <ESC+.> instead)

cd !$

clear command line to start


clear command line to end


jump to end of line


jump to start of line


upper case to end of word


lower case to end of word


word forward


word backward


run last command containing word


first parameter of last command


all arguments of the previous command


third argument from the command before the last one


search history(can be repeated)


Standard Error Redirection

1 represents stdout
2 represents stderr

stdout to file :

command > file

stderr to file :

command 2> file

stdout to stderr :

command 1>&2

stderr to stdout :

command 2>&1

stderr and stdout to file :

command > /dev/null 2>&1
command &> /dev/null

BY: Pejman Moghadam
TAG: bash
DATE: 2009-01-16 07:21:03

Pejman Moghadam / General [ TXT ]