Skip to Content

How to add Time Stamp for Command Prompt?

Add timestamp for command prompt in CentOS, Ubuntu, Debian, and SUSE Linux.


Overview:  This article describes how to add timestamps to the command prompt in CentOS, Ubuntu, Debian, and SUSE Linux by editing the appropriate configuration files for each distribution.


  • For Centos, edit .bashrc file and add the line at the end of the file.

[root@centos ~]# vi /etc/bashrc

PS1="[\u@\h \D{%Y%m%d-%H:%M:%S}]\$ "

An example of the timestamp in Centos:-
 

[root@centos ~]# vi /etc/bashrc

PS1="[\u@\h \D{%Y%m%d-%H:%M:%S}]\$ "

[root@centos 20210311-06:57:00]$ uptime

06:57:04 up 14:41, 3 users, load average: 0.00, 0.01, 0.05

[root@centos 20210311-06:57:04]$


  •  For Ubuntu and Debian, create /etc/bashrc file and add the below line at end of the file.

root@ubuntu:~# vi /etc/bashrc

PS1="[\u@\h \D{%Y%m%d-%H:%M:%S}]\$ "

1. For the root user, edit the .bashrc file and add the below lines at the end of the file.
 

root@ubuntu:~# vi /root/.bashrc

if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

2. For other users, edit .bashrc in the user's home directory and add the below line at the end of the file.
 

xander@ubuntu:~# vi /home/xander/.bashrc

if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

An example of a timestamp for a root user in Ubuntu:-
 

[root@ubuntu 20210313-01:47:56]$ uptime

01:48:00 up 3 days, 1:54, 4 users, load average: 0.08, 0.05, 0.01

[root@ubuntu 20210313-01:48:00]$


  • For SUSE Linux, edit .profile file of root and add below line at end of the file,

root@suse:~$ vi /etc/profile

PS1="[\u@\h \D{%Y%m%d-%H:%M:%S}]\$ " 

 For other users,   edit .bashrc in the user's home directory and add the below line at the end of the file.
 

xander@suse:~# vi /home/xander/.bashrc

PS1="[\u@\h \D{%Y%m%d-%H:%M:%S}]\$ "

 An example for a normal user in SUSE Linux:-
 

[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]#


Related Articles:

Error logs and configuration files.