'less' command as a substitution for 'tail -f'

March 31, 2015
Here is a useful substitution to the popular 'tail -f' command used by many Linux users.

The 'tail' command is used to view the last part of a text file. So if you want to see the last 5 lines in a text file named 'log.txt' then you do the following.

$ tail -n 5 log.txt

The '-f' modifier is very popular because it watches the text file in real time for any changes and displays those on the screen.

So to watch for any new input to the file 'log.txt' you can do the following.

$ tail -f log.txt

However, one disadvantage this method has is that if you want to see the data that has already scrolled out of view in your screen, you will have to come out of the command, open the file in a text editor and view it.

The 'less +F' command overcomes the drawback of the 'tail -f' command.

So to watch the same file using 'less', you do the following.

$ less +F log.txt

To go to normal less, you press 'Ctrl+C' and for moving back to watch mode, you press 'F'.

For a detailed explanation of this tip, visit  brianstorti.com.