TroodoN-Mike
TroodoN-Mike

Reputation: 16165

How to show time next to the command line in terminal/console

When I execute command line (linux) I want to know what time there were executed when I scroll up my terminal window. I saw this once setup in linux environment but how to do that?

Time before command line

Upvotes: 2

Views: 8184

Answers (6)

Gaurav Singh
Gaurav Singh

Reputation: 31

1) Open bashrc file

gedit ~\.bashrc

2) Find the following text:

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] :\[\033[01;34m\]\w\[\033[00m\]\$ ' 

3) And replace with:

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\] [\d|\t]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 

4) Restart terminal to check.

Sample output in terminal

Upvotes: 3

Manoj
Manoj

Reputation: 121

If you would love to show it in the below format:

YYYY-MM-DD HH:MM:SS {domain}@{userId}:~/{folder1}/{folder2}$

export PS1='\D{%F %T} \$\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'

Upvotes: 2

NKD
NKD

Reputation: 21

more simple solution

export PS1='\D{%F %T} \u@\h:\W\$'

Upvotes: 0

Flabio Mirelez
Flabio Mirelez

Reputation: 1

Right now I have my terminal with this configuration:

[hh:mm:ss] PC@User:~$

This can be achieved putting the following instruction on file ~/.bashrc

export PS1="[\$(date +%k:%M:%S)] [\e]0;\u@\h: \w\a]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "

I hope it works for you.

Upvotes: 0

anubhava
anubhava

Reputation: 785058

You can setup PS1 to always show current time in BASH;

export PS1='\A-\w>'
  • \A - current time stamp without seconds part
  • \t - current time stamp with seconds
  • \w - current directory

Upvotes: 5

jaypal singh
jaypal singh

Reputation: 77095

You need to set your prompt variable (PS1). Something like the following should get you going:

<~/temp>$ export PS1="[\$(date +%k:%M)]> "
[12:16]> 

Upvotes: 7

Related Questions