Logo 61e73bc61c0e1780102320e879dc3cac0e29303ea8894dd8f10c942f3ba8120f


An adorable little blog

Watching Files Live

Sunday — April 2nd, 2017

Terminal app icon OS X

If you’re like me, when it’s time to deploy an app or service you’re frantically refreshing log files waiting for something to go horribly awry. Constantly opening and closing the same files to see if anything has changed. Luckily, there is a better way that works whether you’re on macOS, Linux, or BSD!

Normally, if we want to view a file in a Unix-y terminal we could use the less or more command. (Fun fact: On many systems, calls to more are actually just calls to less in disguise!) If we want to view a file with live updates there’s a flag for that.

If we wanted to watch a file called my_log_file in the /var/log directory, we could use the +F flag like so:

less +F /var/log/my_log_file

When you're ready to leave, you can press Ctrl-c to exit the live mode and then you can press q to leave less. Easy as that! Now you can sit, settle down, and have another cup of coffee the next time deployment goes up in smoke. ☕️