how to continuously display a file of its last several lines of contents how to continuously display a file of its last several lines of contents linux linux

how to continuously display a file of its last several lines of contents


I use this function all the time to monitor a log file in another terminal window.

tail -f <filename>

I recommend taking it a step forward to look for particular text in the log. Great if you are only interested in seeing some particular entry being written to the file.

tail -f <filename> | grep <keyword or pattern>


This will update every 2 seconds rather than whenever data is written to the file, but perhaps that's adequate:

watch 'head -n 2 job.sta; tail job.sta'


You can use screen to simulate the expected behaviour:

  1. Run screen, press Space.

  2. Press Ctrl+a followed by S to split the screen.

  3. Resize the top window by pressing Ctrl+a followed by :resize 4.

  4. In the prompt in the top window, enter head -n2 file.

  5. Move to the bottom window by pressing Ctrl+a followed by Tab.

  6. Start a new screen session by pressing Ctrl+a followed by c.

  7. In the new prompt, enter tail -f file.