Code # Of the clear screen and cursor reset command Create_log.sh #! /Bin/bash while true do date> log.txt sleep 1 done; append the content Print_log.sh to log.txt without interrupting the script #! /Bin/bash while true do echo-e "\ 033 [2J \ 033 [1; 1 h 'Tail log.txt '" sleep 1 done; Use the script to read the last 10 lines of log.txt and print it to the console, clear the screen before each printing, and reset the cursor position \ 033 [2J to clear the screen \ 033 [1; 1 H to set the cursor position to y = 1, x = 1, that is, the execution result in the upper left corner of the screen: no second screen display countdown 10 rows Result code May 17, 2013 Friday 09:24:37 CST May 17, 2013 Friday 09:24:38 CST May 17, 2013 Friday 09:24:39 CST May 17, 2013 Friday 09:24:40 CST May 17, 2013 09:24:41 CST May 17, 2013 Friday 09:24:42 CST May 17, 2013 09:24:43 CST May 17, 2013 Friday 09:24:44 CST Friday May 17, 2013 09:24:45 CST Friday May 17, 2013 09:24:46 CST