I know tail prints the last few lines of a file. I read the documentation for tail
man tail and it says
the
-foption 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?
3 Answers
When you're viewing a log file that's being generated by a running process.
0-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.
It is used while checking the logs. Suppose your application is deployed on some server and your application is generating some logs now if you want to see what is going on for a particular request (may be for debugging purpose) than you have two ways to do it :- 1. open the log file and check line by line . 2. use tail -f log.txt and you got the logs for that particular request . It really helps a lot while debugging.