前两天,在知乎的一个问答中(上Unix / 类 Unix shell 中有哪些很酷很冷门很少用很有用的命令?),看到有人在回复中推荐commandlinefu.com这个网站,回头就收藏了,这个网站是介绍一些常用或者很技巧的一些命令:

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

今天在上面看到一篇很有意思的文章,介绍了如何在终端上显示时间:Put a console clock in top right corner。文中给出了两种方法,一种是利用ANSI Escape Sequences,另外一种是通过tput这个命令。

第一种方法

命令如下:

while true; do echo -ne "\e[s\e[0;$((COLUMNS-27))H$(date)\e[u"; sleep 1; done &

查看全文