Questions tagged [tail]

The tail is the part of a list that comes after the head. It's also a unix command that shows the last lines of a file.

Depending on the context tail may refer to:

  • the part of a list that comes after the head i.e. the list you obtain when you remove the first element.

  • the tail unix command which displays the last lines of a file. It's counterpart which displays the first lines is head (). Example: tail -n 10 file will output last 10 lines of file.


See also:

1032 questions
40
votes
9 answers

How do I get the last non-empty line of a file using tail in Bash?

How do I get the last non-empty line using tail under Bash shell? For example, my_file.txt looks like this: hello hola bonjour (empty line) (empty line) Obviously, if I do tail -n 1 my_file.txt I will get an empty line. In my case I want…
Debugger
  • 9,130
  • 17
  • 45
  • 53
36
votes
6 answers

Get last n lines or bytes of a huge file in Windows (like Unix's tail). Avoid time consuming options

I need to retrieve the last n lines of huge files (1-4 Gb), in Windows 7. Due to corporate restrictions, I cannot run any command that is not built-in. The problem is that all solutions I found appear to read the whole file, so they are extremely…
35
votes
6 answers

how to continuously display a file of its last several lines of contents

I am trying to find a Unix command (combination, maybe) on how to continuously display a file of its last several lines of contents. But during this displaying, I want some of the top lines are always displayed on the screen top when the rolling…
Wen_CSE
  • 1,225
  • 2
  • 10
  • 8
33
votes
4 answers

How can I get the source code for the linux utility tail?

this command is really very useful but where I can get the source code to see what is going on inside . thanks .
Haiyuan Zhang
  • 40,802
  • 41
  • 107
  • 134
32
votes
2 answers

Piping tail output though grep twice

Going with a typical Apache access log, you can run: tail -f access_log | grep "127.0.0.1" Which will only show you the logs (as they are created) for the specified IP address. But why does this fail when you pipe it though grep a second time, to…
Craig Francis
  • 1,855
  • 3
  • 22
  • 35
30
votes
1 answer

How to make tail display only the lines that have a specific text?

How to make tail display only the lines that have a specific text? If the search criteria can be a regular expression, it would be even better. I need something like: tail -f mylogfile.log showOnlyLinesWith "error: " I am running Darwin (Mac OS X)…
blagus
  • 2,086
  • 4
  • 19
  • 22
30
votes
10 answers

How to implement a pythonic equivalent of tail -F?

What is the pythonic way of watching the tail end of a growing file for the occurrence of certain keywords? In shell I might say: tail -f "$file" | grep "$string" | while read hit; do #stuff done
pra
  • 8,479
  • 2
  • 18
  • 15
29
votes
18 answers

Ending tail -f started in a shell script

I have the following. A Java process writing logs to the stdout A shell script starting the Java process Another shell script which executes the previous one and redirects the log I check the log file with the tail -f command for the success…
rangalo
  • 5,448
  • 8
  • 46
  • 66
28
votes
9 answers

python pandas select both head and tail

For a DataFrame in Pandas, how can I select both the first 5 values and last 5 values? For example In [11]: df Out[11]: A B C 2012-11-29 0 0 0 2012-11-30 1 1 1 2012-12-01 2 2 2 2012-12-02 3 3 3 2012-12-03 4 4 4 2012-12-04 …
fu xue
  • 361
  • 1
  • 3
  • 10
27
votes
10 answers

Do a tail -F until matching a pattern

I want to do a tail -F on a file until matching a pattern. I found a way using awk, but IMHO my command is not really clean. The problem is that I need to do it in only one line, because of some limitations. tail -n +0 -F /tmp/foo | \ awk -W…
Sam Alba
  • 861
  • 1
  • 9
  • 10
27
votes
4 answers

How do I make a function involving futures tail recursive?

In my Scala app, I have a function that calls a function which returns a result of type Future[T]. I need to pass the mapped result in my recursive function call. I want this to be tail recursive, but the map (or flatMap) is breaking the ability…
Donuts
  • 2,185
  • 3
  • 20
  • 31
26
votes
2 answers

Tail -f + grep?

Tail has the following options: -f The -f option causes tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the input. The -f option is ignored if the standard input is a pipe,…
Sten Kin
  • 2,485
  • 3
  • 23
  • 29
26
votes
5 answers

Grep a Log file for the last occurrence of a string between two strings

I have a log file trace.log. In it I need to grep for the content contained within the strings and . There are multiple sets of this pair of strings, and I just need to return the content between last set (in other words, from the tail…
rs79
  • 2,311
  • 2
  • 33
  • 39
23
votes
4 answers

How can I use tail utility to view a log file that is frequently recreated

I need a solution in creating a script to tail a log file that is recreated (with the same name) after it reaches a certain size. Using "tail -f" causes the tailing to stop when the file is recreated/rotated. What I would like to do is create a…
gfunk
  • 231
  • 1
  • 2
  • 3
23
votes
1 answer

grep for text with wild card in between

I would like to grep something like ==> *.sh <==. But it doesn't work, I can grep everything up to .sh <== but not get the wild card to work. What's the trick here?
beatbreaker
  • 349
  • 2
  • 5
  • 9
1
2
3
68 69