I know there was a command on Unix that I could use to monitor a file and see changes that are getting written to it. This was quite useful especially for checking log files.
Do you know what it is called?
|
I know there was a command on Unix that I could use to monitor a file and see changes that are getting written to it. This was quite useful especially for checking log files. Do you know what it is called? |
|||
|
|
|
|
|||||||||||||||||
|
|
You probably meant tail, as per Jon Skeet's answer. Another useful one is watch; it allows you to run a command periodically and see the output full screen. For example: watch -n 10 -d ls -l /var/adm/messages Will run the command |
|||
|
|
|
Tail is great ... less can also be used start less on the file i.e. less myfile then press F. This has less act as tail. |
|||||||
|
|
I prefer using
I wish there were a command line option to follow a file immediately on startup, but there isn't. Instead, I run |
|||||
|
|
I'm editing a LaTeX file and wanted to monitor it also for changes somewhere in the middle. I whipped up the following little shell script that proved useful to me. I hope it'll also come in handy to someone else.
Save it as
If you want the command only to be run if actual modification takes place, you can use |
|||
|
|
|
You can also use inotifywatch/inotifywait which hook into the kernels inotify subsystem. This way you can also watch for things like "open", "close" or "access". But if you're simply want to get appended lines to stdout i agree on tail. |
|||
|
|
|
Tail is the standard, traditional, available everywhere unix tool. A little more sophisticated tool is multitail which can monitor several files simultaneously and does syntax highlighting. |
|||
|
|
|
If I want to be able to search around the file in addition to just tailing it, I use less with the "F" command. When using tail, keep in mind that additional arguments are needed if the file might be rolling over or replaced by edit (default mode for vim's :w). tail -f will cause tail to store the file descriptor and follow it. If the file is replaced the descriptor will be changed. The benefit of following the file descriptor is that if the file is renamed, you will still be following it. tail --follow= will make tail track the named file by reopening it periodically to see if it has been replaced. --retry is another useful option if you want to tail a log file but the file hasn't been created yet. tail -F is a shortcut for --follow= --retry. |
|||
|
|