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.

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

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

 
An example of 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 root user, edit .bashrc file and add below lines at end of the file.

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

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

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

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

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

 
An example of timestamp for 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 home directory of user and add the below line at 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]#

0 (0)
Article Rating (No Votes)
Rate this article
    Attached Files
    There are no attachments for this article.
    Related Articles RSS Feed
    Password management and the different options.
    Viewed 3874 times since Wed, Jun 14, 2017
    How do i add in bastion server into the ssh gateway when i don’t know its password?
    Viewed 2219 times since Wed, Jun 14, 2017
    Disable dns for server hostname while adding in servers and for control panel access
    Viewed 2370 times since Wed, Jun 14, 2017
    server root password mass reset - Is there any risks for corruption?
    Viewed 2177 times since Thu, Jun 15, 2017
    default ssh public key to add in target server or Linux instances for ssh key based authentication
    Viewed 2933 times since Wed, Jun 14, 2017
    Internal command ezinfo or ezlist does not work even though i am in the admins group.
    Viewed 3579 times since Thu, Nov 23, 2017
    How to grant a user access to control panel
    Viewed 2242 times since Thu, Jun 15, 2017
    Webportals unavailable for user
    Viewed 4033 times since Fri, Dec 8, 2017
    How to enforce 2 Factor Authentication on user login?
    Viewed 2692 times since Wed, Sep 19, 2018
    How to grant Parallel Shell privilege for a user?
    Viewed 4718 times since Wed, Nov 22, 2017