Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the -f flag in tail do?

Tags:

terminal

unix

I know tail prints the last few lines of a file. I read the documentation for tail

man tail

and it says

the -f option causes a tail to not stop when end of file is reached but rather to wait for additional data to be appended to the input.

I tested the commands

tail -f sample.txt

and

tail sample.txt

and saw what the difference was. But can someone provide a real life example of why they would use tail -f instead of just tail?

like image 331
User314159 Avatar asked Jun 14 '13 19:06

User314159


2 Answers

-f is used for when you have an expectation that someone will come along and append to the file while you are watching it. Most commonly it is used in log files (loggers will add lines to the end of files and this is great for watching those), but I've also used it to watch information appended to a CSV file.

like image 105
cwallenpoole Avatar answered Nov 08 '22 10:11

cwallenpoole


When you're viewing a log file that's being generated by a running process.

like image 31
Oliver Charlesworth Avatar answered Nov 08 '22 10:11

Oliver Charlesworth