To monitor log files in real-time, the tail -f command is the perfect tool. Here is how it works and how you can use it:
1. Run the command
In your terminal, type the following and press Enter:
tail -f /home/labex/project/system.log
The terminal will display the last 10 lines of the file and stay open. It is now "following" the file.
2. Witness real-time updates
Unlike a normal command that finishes immediately, tail -f waits for the file to grow. To see this in action:
- Keep the
tail -fterminal open. - Open a second terminal tab or window.
- Run a command to add text to that file, like:
echo "$(date) [INFO] Real-time test entry" >> /home/labex/project/system.log - Look back at your first terminal. You will see the new line appear instantly without you having to re-run any commands!
3. How to stop monitoring
Since the command remains active to keep watching the file, you need to manually stop it when you are finished.
- Press
Ctrl + Con your keyboard to terminate the process and return to the command prompt.
Why is this useful?
System administrators use this constantly to watch software logs during a crash or to see if a web server is receiving requests as they happen. It saves you from having to manually open the file over and over again