Dynamic clock in linux shell

Source: Internet
Author: User
Tags setf

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.