2

Is it possible to execute cat logfile | tail -f? For some reason it just reads the initial log, but then it doesn't update incoming entries. I know I can directly do tail -f logfile.

I just wanted to know why this doesn't work, and if tail -f has to be always first and then another pipe?

1
  • 1
    It's a good idea to get out of the habit of using cat uselessly. Dec 10, 2010 at 16:57

1 Answer 1

5

Just do tail -f logfile. When you do the cat first, you are cating the file as it is right now, and if you want to get new entries, you'll need to cat it again. If you just do tail -f logfile, then it will continually update the screen as the file updates (although you may wish to do tail -F logfile, so it will continue to work if the logfile is rolled over and a new one is created).

In other words, cat executes once and the output goes to tail. Running tail directly on the file causes tail to execute and stay running, so you continually get updates (with -f, that is).

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.