Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using RHEL 4.

The normal tail -F file_name*.log doesn't update when the time flips over to 0000.

Here's what I've tried so far from searching the web, both of which try to use nested tail:

tail -F $(ls -tr file_name*.log | tail -n 1)

tail -F $(fine . -maxdepth 1 -type f -printf "%T@ %p\n" | sort -n | tail n 1 | cut -d' ' -f 2-)

None of these flip over to new files. Plain old tail -F file_name*.log works in my small test cases (while the 2 above don't), but it doesn't work when I'm tailing a real log file.

share|improve this question
What exactly are you trying to do? If you are trying to continually tail a file despite a log-rotate taking effect, tail -F filename.log is what you want. I am not following what you are trying to do with all of the extra nesting. – sparticvs Nov 3 '12 at 3:10
up vote 4 down vote accepted

This won't (can't) work - the sub-shells you're using to determine the latest file only get executed once. The glob won't work because the shell evaluates the wild-card only ONCE.

One way to deal with it would be to use 'watch' to run the whole thing, but that would hack up the output every so many seconds.

share|improve this answer
Ah, I'll just go about writing some script for it then. Thanks! – Ken Oh Nov 3 '12 at 5:59

You're probably going to have to write something to follow tail. Or configure your system to not roll logs (or that log) at midnight. Either way, the filehandle of the tailed logfile is reset when it's rolled.

share|improve this answer

tail monitors a single file, or at most a set of files that is determined when it starts up. In the command tail -F file_name*.log, first the shell expands the wildcard pattern, then tail is called on whatever file(s) exist at the time.

To monitor a set of files based on wildcards, you can use multitail.

multitail -iw 'file_name*.log' 1
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.