Questions tagged [tail]

Watching updates at the end of a file, with or without the tail utility

To tail a file means to keep it open and watch new lines that are appended to it by some other program.

tail is a classic Unix text processing utility which displays the last few lines of a file. It introduced “follow mode”, where the file is kept open and the utility prints new lines as they appear.

Use this tag when tailing files, regardless of whether you are using the tail utility itself. A question about using tail which isn't about follow mode should probably use the tag. Not to be confused with the Tails operating system . For monitoring of changes to files in general, see .

Common tailing utilities

Further reading

412 questions
319
votes
23 answers

How to have tail -f show colored output

I'd like to be able to tail the output of a server log file that has messages like: INFO SEVERE etc, and if it's SEVERE, show the line in red; if it's INFO, in green. What kind of alias can I setup for a tail command that would help me do this?
Amir Afghani
  • 7,083
  • 11
  • 26
  • 23
189
votes
8 answers

cat line X to line Y on a huge file

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010). From what I understand I can do this by piping head into tail or viceversa, i.e. head -A /path/to/file | tail -B or alternatively tail -C…
Amelio Vazquez-Reina
  • 40,169
  • 77
  • 197
  • 294
146
votes
6 answers

How to monitor only the last n lines of a log file?

I have a growing log file for which I want to display only the last 15 lines. Here is what I know I can do: tail -n 15 -F mylogfile.txt As the log file is filled, tail appends the last lines to the display. I am looking for a solution that only…
Marc-Olivier Titeux
  • 1,593
  • 2
  • 10
  • 8
142
votes
1 answer

How to do a `tail -f` of log rotated files?

On a long running system I usually have a terminal with $ tail -f /var/log/kern.log or something like this open. But from time to time I have to restart such command because no new messages are displayed anymore. I assume this is because of the log…
maxschlepzig
  • 56,316
  • 50
  • 205
  • 279
119
votes
5 answers

Does tail read the whole file?

If I want to tail a 25 GB textfile, does the tail command read the whole file? Since a file might be scattered on a disk I imagine it has to, but I do not understand such internals well.
The Unfun Cat
  • 3,341
  • 9
  • 30
  • 40
88
votes
3 answers

The 'less' command-line equivalent of 'tail -f'

I would like to open up a file using less, and have it automatically scroll the file similar to tail -f. I know that I can do less file, and then hit Shift-F to forward forever; like tail -f. I need less because it provides the --raw-control-chars…
Stefan Lasiewski
  • 19,264
  • 24
  • 70
  • 85
85
votes
5 answers

Combining tail && journalctl

I'm tailing logs of my own app and postgres. tail -f /tmp/myapp.log /var/log/postgresql/postgresql.main.log I need to include pgpool's logs. It used to be syslog but now it is in journalctl. Is there a way to tie tail -f && journalctl -f together?
bikey
  • 851
  • 1
  • 6
  • 4
74
votes
3 answers

How does the "tail" command's "-f" parameter work?

$ tail -f testfile the command is supposed to show the latest entries in the specified file, in real-time right? But that's not happening. Please correct me, if what I intend it to do is wrong... I created a new file "aaa" and added a line of text…
its_me
  • 13,709
  • 23
  • 54
  • 52
72
votes
3 answers

Observe multiple log files in one output

Is there an easy way to do something like tail -f mylogfile but to have the changes of more than one file displayed (maybe with the file name added as prefix to each line)? Or maybe a GUI tool? I am running Debian.
stofl
  • 823
  • 1
  • 6
  • 5
72
votes
5 answers

Output file contents while they change

I want to output a file's contents while they change, for example if I have the file foobar and I do: magic_command foobar The current terminal should display the file's contents and wait until, I don't know, I press ^C. Then if from another…
Paul
  • 823
  • 1
  • 6
  • 6
72
votes
8 answers

grep and tail -f?

Is it possible to do a tail -f (or similar) on a file, and grep it at the same time? I wouldn't mind other commands just looking for that kind of behavior.
xenoterracide
  • 57,918
  • 74
  • 184
  • 250
72
votes
10 answers

How to obtain inverse behavior for `tail` and `head`?

Is there a way to head/tail a document and get the reverse output; because you don't know how many lines there are in a document? I.e. I just want to get everything but the first 2 lines of foo.txt to append to another document.
chrisjlee
  • 8,283
  • 16
  • 49
  • 54
70
votes
8 answers

monitor files (à la tail -f) in an entire directory (even new ones)

I normally watch many logs in a directory doing tail -f directory/*. The problem is that a new log is created after that, it will not show in the screen (because * was expanded already). Is there a way to monitor every file in a directory, even…
santiagozky
  • 803
  • 1
  • 6
  • 5
67
votes
5 answers

Grep from the end of a file to the beginning

I have a file with about 30.000.000 lines (Radius Accounting) and I need to find the last match of a given pattern. The command: tac accounting.log | grep $pattern gives what I need, but it's too slow because the OS has to first read the whole…
tijuco
  • 801
  • 1
  • 6
  • 5
66
votes
3 answers

Does "less" have a feature like "tail --follow=name" ("-F")

The command less can be used to replace tail in tail -f file to provide features like handling binary output and navigating the scrollback: less +F file The + prefix means "pretend I type that after startup", and the key F starts following. But…
Volker Siegel
  • 16,983
  • 5
  • 52
  • 79
1
2 3
27 28