I recently looked at some things about linux shell. Occasionally, I found it online when I realized a dynamic clock on the terminal.
Http://blog.csdn.net/reage11/article/details/8586200 this blog can easily understand, But I carefully read his code, found that do not need to use the switch to determine the month, the greatness of the Linux Command has exceeded our imagination, therefore, I modify the Code as follows:
#!/bin/bashtput civiswhile [ 1 ]do tput clear tput cup 3 10 tput setb 0 tput setf 2 echo $(date "+%Y--%m--%d %H:%M:%S %A") sleep 1done
The original article is as follows:
#!/bin/bash tput civis while [ 1 ] do nonth=$(date +%B) case "$nonth" in January) nonth=1;; February) nonth=2;; March) nonth=3;; April) nonth=4;; May) nonth=5;; June) nonth=6;; July) nonth=7;; August) nonth=8;; September) nonth=9;; October) nonth=10;; November) nonth=11;; December) nonth=12;; esac tput clear tput cup 3 10 echo $(date +%Y)--$nonth--$(date +%d) $(date +%H):$(date +%M):$(date +%S) $(date +%A) sleep 1 done
Related Knowledge (copied from the above link ):
Tput command parameters:
Tput civis: used to hide the cursor
Tput cols: displays the current column
Tput lines: displays the current row
Tput cup lines cols: move the cursor to lines and cols
Tput setb no: Set the terminal background color. Value of no will be introduced later
Tput setf no: Set the text color. Value of no will be introduced later
Tput ed: Delete the content from the current cursor to the end of the row
Value of no:0:Black,1:Blue,2:Green, 3:Cyan,4:Red,5:Magenta,6:Yellow,7:White
For more information, see man tput.
Date Command Parameters
% H: hour (0 .. 23) % I: hour (01 .. 12) % M: minute (0 .. 59) % p: displays the local time period "Morning" or "Afternoon" % r: displays the time directly (in 12-hour format: hh: mm: ss [AP] M) % s: number of seconds from January 1, 1970 00:00:00 UTC till now % S: Second (00 .. 61) % X: equivalent to % H: % M: % S % a: day of the week (Mon .. sun) % A: The day of the week (Monday .. sunday) % B: Month (Jan .. dec) % B: Month (January .. december) % c: Display date and time % d: Day (01 .. 31) % D: Display date directly (mm/dd/yy) % j: day of the year (001 .. 366) % m: Month (01 .. 12) % x: Date (mm/dd/yy) % y: last two digits of the Year (00.99) % Y: complete year (0000 .. 9999)