Harness the Combinatoric Power of Command-Line Tools and Utilities

../Tips

Follow Log Files With Less

commands files

Published May 17, 2024

Warning

❗ This article is more than six months old. Some things may not work as written.

When you’re working with a development server or a system log, you may want to watch the log for changes and see them streamed to your terminal window.

The tail -f command reads and follows a file, printing new lines to the screen. It’s somewhat limited though, because you have to rely on your terminal buffer to scroll up and see changes you may have missed.

The less command can also follow a file for changes.

less +F /var/log/system.log

The output displays the log:

May 17 13:42:53 Chimaera syslogd[327]: ASL Sender Statistics
May 17 14:01:55 Chimaera syslogd[327]: ASL Sender Statistics
Waiting for data... (^X or interrupt to abort)

While following the log, you won’t be able to scroll or navigate. Press CTRL+C or CTRL+X to stop following so you can navigate through the log’s contents.

Press SHIFT+F to resume following the log again.

To exit, press CTRL+C to stop following the log, and then press q to quit.