How to add Time Stamp for Command Prompt?
How to add timestamp for command prompt in CentOS, Ubuntu, Debian and SUSE Linux?
For Centos, edit bashrc file and add the line at end of the file.
[[email protected] ~]# vi /etc/bashrc
PS1="[\[email protected]\h \D{%Y%m%d-%H:%M:%S}]\$ "
[[email protected] ~]# vi /etc/bashrc
PS1="[\[email protected]\h \D{%Y%m%d-%H:%M:%S}]\$ "
[[email protected] 20210311-06:57:00]$ uptime
06:57:04 up 14:41, 3 users, load average: 0.00, 0.01, 0.05
[[email protected] 20210311-06:57:04]$
[email protected]:~# vi /etc/bashrc
PS1="[\[email protected]\h \D{%Y%m%d-%H:%M:%S}]\$ "
[email protected]:~# vi /root/.bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
xander@ubuntu:~# vi /home/xander/.bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
[[email protected] 20210313-01:47:56]$ uptime
01:48:00 up 3 days, 1:54, 4 users, load average: 0.08, 0.05, 0.01
[[email protected] 20210313-01:48:00]$
For SUSE Linux, edit .profile file of root and add below line at end of the file,
[email protected]:~$ vi /etc/profile
PS1="[\[email protected]\h \D{%Y%m%d-%H:%M:%S}]\$ "
xander@suse:~# vi /home/xander/.bashrc
PS1="[\[email protected]\h \D{%Y%m%d-%H:%M:%S}]\$ "
[xander@suse 20210313-01:47:56]# uptime
01:48:00 up 3 days, 1:54, 4 users, load average: 0.08, 0.05, 0.01
[xander@suse 20210313-01:48:00]#