Search code examples
unixloggingtail

tail -f aFile.log | grep astring stops executing when the log file is rotated


I am using the below command to search through a stream of data being generated. The log file is generated by a long running process and the log mechanism keeps rotating the log file. So, the current file 'aFile.log' will be renamed to 'aFile.log.1' based on certain criteria(such as file size or time change) and a new 'aFile.log' will be created. The following command just hangs in there. Is there a work around for this?

tail -f aFile.log | grep aString

Solution

  • Use -F instead of -f to track by filename.

    tail -F aFile.log | grep aString