How to tail -f real time file.

How to tail -f real time file.

I want to tail file created last time.
The server is gen new file Always.

.

An example file.

-rw-r--r--  1 shinnie tiituck 251M Oct 18 05:39 20111018_00.log
-rw-r--r--  1 shinnie tiituck 251M Oct 18 11:18 20111018_01.log
-rw-r--r--  1 shinnie tiituck 250M Oct 18 16:56 20111018_02.log
-rw-r--r--  1 shinnie tiituck 251M Oct 18 22:34 20111018_03.log
-rw-r--r--  1 shinnie tiituck  64M Oct 18 23:59 20111018_04.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 05:38 20111019_00.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 11:17 20111019_01.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 16:48 20111019_02.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 22:25 20111019_03.log
-rw-r--r--  1 shinnie tiituck  70M Oct 19 23:59 20111019_04.log


I can use this command it.

tail -f 201110??_??.log |grep "same key word"

If you want to know the most recent file:

mLast=$(ls -1tr 20*.log | tail -1)
tail -f ${mLast} ...

This might help you:

ls -ltr|head -1|awk '{print $9}'|tail -f

I am not sure why you would add the "-l" (long listing) which makes you use awk to remove the columns given with a long listing. You could remove the "-r" (reverse order) and "-l" (long listing) flags and use the "-w1" or "-1" (force 1 column width/1 file per line) for a better method would be:

ls -tw1|head -1|tail -f

or

ls -t1|head -1|tail -f

With an "ls" based command string you would have the added risk of finding directories as well as files. If someone were to create a directory after the last logfile was created and then that script/command ran you would get unexpected results.