Alias to open latest log file in Bash shell

Here’s a simple bash alias to open last modified log file in logs directory. It will be opened in less pager on last line:

alias log='less +G $(ls -ctr1 $APP_HOME/logs/*.log | tail -1)'

You can put it somewhere in ~/.bashrc or ~/.bash_profile and declare $APP_HOME somewhere above this line. You might also need to change /logs/*.log path.

Save file. Run source ~/.bashrc, and you’ll see last modified log anytime you call log command.

You can also substitute less +G with tail -f and open log in follow mode (it will automatically show anything new written to file)

%d bloggers like this: