The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 84,032β€…    Votes:  2β€…
Tags: command-line   gnome-terminal  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1164893
Title: How to show a running clock in terminal before the command prompt
ID: /2019/08/11/How-to-show-a-running-clock-in-terminal-before-the-command-prompt
Created: August 11, 2019
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


If you never need to use debian_chroot then it’s a handy place to put the time the command prompt was displayed by using:

export PROMPT_COMMAND='debian_chroot=$(date +%r)'

Type this in your terminal and watch your command prompt change with the time:

rick@alien:~$ export PROMPT_COMMAND='debian_chroot=$(date +%r)'

(09:14:59 PM)rick@alien:~$ 

After the time is set once, to get a running clock which updates every second use:

while sleep 1;do tput sc;tput cup $(($(tput lines)-1)) 1;printf `date +%r`;tput rc;done &

This .gif shows the commands in action:

Time terminal prompt.gif

⇧ How do I enable docker as a service without re-installing docker? How to change Gnome-Terminal title?  β‡©