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)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: