This script will add a grey dashed line with the date and time at the end of the line, then it will change to red if you run as a root user:

Add the following lines to the bottom of both /home/<username>/.bashrc
and /root/.bashrc
files (NOTE: /root/.bashrc
has to be edited with root capabilities like sudo gedit /root/.bashrc
):
if [ -f "$HOME/.bash_ps1" ]; then
. "$HOME/.bash_ps1"
fi
Copy and paste the following code to a new file called /home/<username>/.bash_ps1
:
# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="--- "
reset_style='\[\033[00m\]'
# determine if root or not
a=$(id -u)
if [ "$a" = 0 ]
then
# for root
status_style=$reset_style'\[\033[1;31m\]' # bold red; use 0;37m for lighter color
command_style=$reset_style'\[\033[1;31m\]' # bold red
else
# for other users
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
command_style=$reset_style'\[\033[1;29m\]' # bold black
fi
prompt_style=$reset_style
# Prompt variable:
PS1="$status_style"'$fill $(date +"%m/%d/%y ")\t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\033[00m"' DEBUG
function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-18
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=$(basename "${PWD/$HOME/~}")
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
PROMPT_COMMAND=prompt_command
Next, create a link in the /root
folder so that it calls this when switching to the root
user:
sudo -s
cd /root
ln -s /home/<username>/.bash_ps1
After all is saved, now every time you open a new terminal window it should look like the image above. The timestamps appear after you press enter on each command you type into the terminal making it easier to scroll back and see when you ran that specific command.
Hope this helps!