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

后端 未结 5 739
深忆病人
深忆病人 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条回答
  •  自闭症患者
    2020-12-30 08:51

    We have daily rotating log files as: /var/log/grails/customer-2020-01-03.log. To tail the latest one, the following command worked fine for me:

    tail -f /var/log/grails/customer-`date +'%Y-%m-%d'`.log
    

    (NOTE: no space after the + sign in the expression)

    So, for you, the following should work (if you are in the same directory of the logs):

    tail -f SoftwareLog.`date +'%Y-%m-%d-%H'`
    

提交回复
热议问题