How to tail -f the latest log file with a given pattern

后端 未结 5 743
深忆病人
深忆病人 2020-12-30 08:29

I work with some log system which creates a log file every hour, like follows:

SoftwareLog.2010-08-01-08
SoftwareLog.2010-08-01-09
SoftwareLog.2010-08-01-10
         


        
5条回答
  •  Happy的楠姐
    2020-12-30 09:00

    I believe the simplest solution is as follows:

    tail -f `ls -tr | tail -n 1`
    

    Now, if your directory contains other log files like "SystemLog" and you only want the latest "SoftwareLog" file, then you would simply include a grep as follows:

    tail -f `ls -tr | grep SoftwareLog | tail -n 1`
    

提交回复
热议问题