I want to know how to tail a log file when lines in the files are updating(appending and removing)?


As Atari911 said, you can use watch along with cat to do this. Use

watch cat <filename>

this will output the contents of the file given by filename every 2 seconds to standard output. To change the interval for updating the output to something like 1 second(you can't reduce beyond 0.1), you can use

watch -n 1 cat <filename>

I am using cat to output the complete file, you could tail but that would only give you the last n lines of the file, where n is 10 by default.

Refer to the manual page of watch for more info.


You might try:

tail -f /var/log/syslog

Or whatever file you are interested in. Get out of 'tail' with Ctrl+c.

  • This is not working when lines are removing from the file – Lasith Malinga Jan 27 '14 at 15:58
  • 1
    I am unaware of any log file where lines are removed. Which is it? – chili555 Jan 27 '14 at 16:02
  • It's relevant to my application – Lasith Malinga Jan 27 '14 at 16:05

You need to use the tail command which output the last part of files in real time including all incoming logs to a standard output device such as screen. the commadn to use is

tail -f /path/to/log/file

EDIT: TRY this

tail -f --retry /path-to-log-file

This will try to reopen the file with the new contents

Or this

tail -F /path/to/log/file
  • This is not working when lines are removing from the file – Lasith Malinga Jan 27 '14 at 16:00
  • @LasithMalinga check the edit – Maythux Jan 27 '14 at 16:09

I'm not sure exactly what you are trying to do but you could use the watch command in conjunction with the tail command... Something like this:

watch tail /path/to/file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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