| /etc/profile |
System Profile |
| ~/.bash_profile |
Primary User Profile |
| ~/.bash_login |
Alternate User Profile |
| ~/profile |
Second Alternate User Profile |
| ~/.bashrc |
Subshell Profile |
| ~/.bash_logout |
Shell Exit Commands |
. ~/.bash_profile source ~/.bash_profile |
Re-read configuration files |
Environment Variables
[user@host user]$ env
HISTSIZE=1000
HOSTNAME=host
LOGNAME=user
HISTFILESIZE=1000
MAIL=/var/spool/mail/user
TERM=xterm
HOSTTYPE=i386
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin
HOME=/home/user
INPUTRC=/etc/inputrc
SHELL=/bin/bash
PS1=[\u@\h \W]\$
USER=user
LC_ALL=en_US
LANG=en_US
OSTYPE=Linux
LINGUAS=en_US
SHLVL=1
_=/usr/bin/env
[user@host user]$ export MYVAR='hello world'
[user@host user]$ echo $MYVAR
hello world
[user@host user]$ unset MYVAR
[user@host user]$ echo $MYVAR
[user@host user]$ MYVAR='hello world' printenv MYVAR
hello world
[user@host user]$ export CDPATH=:/usr/web
[user@host user]$ ls
[user@host user]$ cd htdocs
/usr/web/htdocs
[user@host htdocs]$
Aliases
[user@host user]$ alias ls='ls --color'
[user@host user]$ alias l='ls -alF'
[user@host user]$ alias cc='/usr/bin/gcc -Wall -ansi -pedantic'
[user@host user]$ alias
alias cc='/usr/bin/gcc -Wall -ansi -pedantic'
alias l='ls -alF'
alias ls='ls --color'
[user@host user]$ unalias cc
[user@host user]$ alias cc
alias: `cc' not found
Options
[user@host user]$ set -o
[user@host user]$ help set
Functions
[user@host user]$ declare -f mc
mc ()
{
mkdir -p ~/.mc/tmp 2>/dev/null;
chmod 700 ~/.mc/tmp;
MC=~/.mc/tmp/mc$$-"$RANDOM";
/usr/bin/mc -P "$@" >"$MC";
cd "`cat $MC`";
rm "$MC";
unset MC
}
[user@host user]$ unset -f mc
[user@host user]$ declare -f mc
[user@host user]$ function demofunc
> {
> echo demofunc got ${#} positional parameters
> while [ ${#} -gt 0 ]
> do
> echo "${1}"
> shift
> done
> }
[user@host user]$ declare -f demofunc
demofunc ()
{
echo demofunc got ${#} positional parameters;
while [ ${#} -gt 0 ]; do
echo "${1}";
shift;
done
}
[user@host user]$ demofunc a b c
demofunc got 3 positional parameters
a
b
c
Misc - Prompting
| \t | the current time in HH:MM:SS format |
| \d | the date in "Weekday Month Date" format (e.g., "Tue May 26") |
| \n | newline |
| \s | the name of the shell, the basename of $0 (the portion following the final slash) |
| \w | the current working directory |
| \W | the basename of the current working directory |
| \u | the username of the current user |
| \h | the hostname |
| \# | the command number of this command |
| \! | the history number of this command |
| \$ | if the effective UID is 0, a #, otherwise a $ |
| \nnn | the character corresponding to the octal number nnn |
| \\ | a backslash |
| \[ | begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt |
| \] | end a sequence of non-printing characters |
My favorite: [user@host user]$ export PS1="\! \t\w> "
Misc - Redirection
Redirect Standard Input
[user@host user]$ sort < /etc/passwd
Redirect Standard Output
[user@host user]$ ls > dirlist
Append to a File
[user@host user]$ ls /etc >> dirlist
Redirect Standard Error
[user@host user]$ ls /no_such_directory 2> /dev/null
Redirect Standard Output and Standard Error
[user@host user]$ ls / /no_such_directory > dirlist 2> /dev/null
Redirect Standard Output and Standard Error to the same place
[user@host user]$ ls / /no_such_directory > dirlist 2>&1
- or -
[user@host user]$ ls / /no_such_directory &> dirlist
Pipeline
[user@host user]$ du -sk * | sort -rn | head -5
Redirect Standard Input and Pipeline
[user@host user]$ awk -F: '{print $7}' < /etc/passwd | sort | uniq
Last updated September 25, 2007