Skip to content

Bash Profile Settings 1

Bash has five prompt strings that can be customized:

  • PS0 -> displayed after each command before any output;
  • PS1 -> primary prompt which is displayed before each command;
  • PS2 -> secondary prompt displayed when a command needs more input (e.g. a multi-line command).
  • PS3 -> not very commonly used. It is the prompt displayed for Bash's select built-in which displays interactive menus. Unlike the other prompts, it does not expand Bash escape sequences. Usually you would customize it in the script where the select is used rather than in your .bashrc.
  • PS4 -> is also not commonly used. It is displayed when debugging bash scripts to indicate levels of indirection. The first character is repeated to indicate deeper levels.

PS1 Color Prompt for Bash

[2017-04-14][20:52:25] [username@hostname]:~
$
  • Modify .bash_profile, .profile, or .bashrc (if using bash)
.bash_profile
export PS1="\[\033[0;33m\][$(date +%Y-%m-%d)][\t]\[\033[0;36m\] [\u\[\033[0;37m\]@\[\033[0;36m\]\h]:\[\033[0;32m\]\w\[\033[0m\] \n$"

alias ls='ls -laGFh'
Colors and Prompt Variables
##### modify standard command prompt
# \n   = new line; 
# \u   = username; 
# \h   = hostname;
# \t   = time;
# \w   = current working dir (home = ~);
# \A   = current time;
# \$?  = exit code/status from previous command;
# \033 = starts all escape sequences (^[ or \x1B)


##### Colors
# Black       0;30     Dark Gray     1;30
# Blue        0;34     Light Blue    1;34
# Green       0;32     Light Green   1;32
# Cyan        0;36     Light Cyan    1;36
# Red         0;31     Light Red     1;31
# Purple      0;35     Light Purple  1;35
# Brown       0;33     Yellow        1;33
# Light Gray  0;37     White         1;37
Linux ls command modifications
##### Modify default ls command
# -G colorizes output
# -h makes sizes human readable
# -F throws a / after a directory, * after an executable, and a @ after a symlink
# -l listing format (as opposed to default wide)
# -a shows all files (even hidden)

More Info