I have a log file in .csv format in Linux, that is being updated continuously. I want to view the log file as it is being updated. Is there any Linux command(s) to do that?
This is such a crucial folder on your Linux systems. Open up a terminal window and issue the command cd /var/log. Now issue the command ls and you will see the logs housed within this directory (Figure 1).
1. tail Command – Monitor Logs in Real Time. As said, tail command is the most common solution to display a log file in real time.
If you want to get the last 1000 lines from a log file and they do not fit into your shell window, you can use the command "more" to be able to view them line by line. press [space] on the keyboard to go to the next line or [ctrl] + [c] to quit.
From the bash prompt, issue the command sudo tail -f /var/log/syslog. Once you've successfully typed your sudo password, you will see that log file presented to you, in real time.
tail -f yourlog.csv
Newly appended lines will continuously show.
As others have pointed out, tail -f file
is the most common solution. The problem is that the results just scroll by, and you can't go back and search them unless your terminal supports it and you have enough lines buffered in your terminal.
A less known solution that I like is to use less
; if you type Shift-F while viewing a file with less
, it will start following the end of the file just like tail -f
. Alternatively, you can start less
with less +F
to enter this mode on startup. At any time, you can type Ctrl-C to stop following the file, and then page up and down, search using /, and use less
just like normal. This can be really helpful if you see something interesting in the log, but it scrolls off screen, or if you want to go back a bit to check on something you might have missed. Once you're done searching around, hit Shift-F again to start following the file again.
multitail
looks like a nice solution for following multiple files in separate windows; if you view multiple files with tail -f
, they will each be interleaved with each other (with headers to distinguish them), which may not be the way you want to watch them.
tail -F
(that is capital -F
, as opposed to lowercase -f
) is a non-standard flag (available on Linux, Cygwin, MacOS X, FreeBSD and NetBSD), that works better for watching log files, which may be rotated occasionally; it's common for a process to rename a log file, and then create a new log file in its place, in order to avoid any one log file getting too big. tail -f
will keep following the old file, which is no longer the active log file, while tail -F
will watch for a new file being created, and start following that instead. If you're using less
to follow the file, you can use the --follow-name
flag to make less
act this way as well.
(thanks to ephemient for the tips on less +F
and less --follow-name
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With