Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I always run tail -F to keep an eye on a log in a terminal window. The log has a UTC date at the beginning of each entry:

[08-Jan-2013 16:24:22] Yo!

When I glance at my log window I need to know how old the entries are. I would prefer not to have to look at my local clock and do the math. So I figured it would be cool to have a real-time clock display in the window along with the tail ouput.

What I came up with was to background a while loop echoing the date and a carriage return. When a log entry is written, tail overwrites the clock.

while true; do echo -ne `date +"[%d-%b-%Y %H:%M:%S]"`"\r"; sleep 1; done &
log -F /path/to/log

This basically works but I'm concerned about what happens when outputs from tail and date produce output at the same time. I don't want my view of the log to be spoiled by the carriage return.

How would I multiplex these outputs together so that they can't collide? Is that a job for screen or something else?

The log is on a remote Debian server. My workstation runs OSX. I'm connecting via SSH to run the script above.

share|improve this question
This seems more like a programming problem than a system administration problem and as such may be better served on Stack Overflow. –  Iain Jan 8 '13 at 17:19
You could use tail -f and then pipe the output to sed to change the text to something else. But first of all changing the time to current time would be difficult, and then, as the text is already on the screen you would need the time to change while displayed on the screen. I would go to something more flexible, like php binary. –  anttiR Jan 8 '13 at 18:02

2 Answers 2

You could use the -s option of tail so that your tail sleeps for say 5 seconds:

-s, --sleep-interval=S
 with -f, sleep for approximately S seconds (default 1.0) between iterations.

tail -s 5 -f /var/log/messages

Or the watch command will show you the date:

watch --interval=5 tail  /var/log/messages

    Every 5.0s: tail /var/log/messages                 Tue Jan  8 17:52:41 2013

Jan 8 17:52:34 localhost kernel: NEW: IN=eth0 OUT= MAC=00:60:56:73:14:6b:00:50:5b:93:49:5d:08:00 SRC= DST= LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=29070 DF PROTO=TCP SPT=50561 DPT=25 WINDOW=5840 RES=0x00 SYN URGP=0

Another (not particularly nice) solution using strace -t command:

 strace -t tail -f /var/log/messages

Finally, you could write your own modified tail command in python/perl/ruby:


and just add date/time read to the output line.

share|improve this answer
See this similar question:serverfault.com/questions/157526/… –  davey Jan 8 '13 at 18:30
Thanks for these. I also just found and tried tmux which I didn't like as much. As it turns out, the code that I posted has been running all day with no conflicts. –  Andy Jan 8 '13 at 22:07

You may want to have a look at multitail; it supports multiple windows with separate or merged log files, regex-based coloring per file type, word-wrap options, filename watch (useful for logrotated files), and more.

Oh, and a clock on the status line.

share|improve this answer
Very nice program! I will find it useful. Still, the clock on the status line only updates when there is output so multitail doesn't meet the goal. I want to know how old the last log entry is without consulting a clock outside the terminal window. If multitail updated the clock or (even cooler) showed the H:M:S since the last entry it would win. –  Andy Jan 15 '13 at 15:11

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.