BASH Prompt Customization

By xngo on June 23, 2019

Customization of the the Bash terminal line

Add the following codes in ~/.bashrc. Every time you open a Bash terminal, the first line will show HH:MM:SS@hostname:workingDirectory # .

export PS1="\t@\H:\w # "
 
export PS1="\n--=[\$(date +%Y-%m-%d)\t@\u]=--\n\w>"
 
# Add yellow color
export PS1="\e[0;33m--=[\$(date +%Y-%m-%d) \t@\u]=--\e[m\n\w>"

Reference: http://www.blacksheepnetworks.com/security/resources/labs/prompts.html

Bash eternal history

Add the following codes in ~/.bashrc. It will save whatever you type in the command line forever in ~/.bash_eternal_history file.

export HISTTIMEFORMAT="%s "
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER \
               "$(history 1)" >> ~/.bash_eternal_history'

Reference: http://www.debian-administration.org/articles/543

# log every command typed and when
if [ -n "${BASH_VERSION}" ]; then
    trap "caller >/dev/null || \
printf '%s\\n' \"\$(date '+%Y-%m-%dT%H:%M:%S%z')\
 \$(tty) \${BASH_COMMAND}\" 2>/dev/null >>~/.command_log" DEBUG
fi

http://serverfault.com/questions/378305/log-every-command-executed-from-root

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.