Category

Linux Command


Usage

tail [OPTION]... [FILE]...


Manual

Print the last 10 lines (other numbers can be assigned by using -n) of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.

Options

  • -c, --bytes=NUM: output the last NUM bytes; alternatively, use -c +NUM to output bytes starting with byte NUM of each file
  • -f, --follow[={name|descriptor}]: output appended data as the file grows; an absent option argument means 'descriptor'
  • -F: same as --follow=name --retry
  • -n, --lines=[+]NUM: output the last NUM lines, instead of the last 10; or use -n +NUM to output lines starting with line NUM
  • --max-unchanged-stats=N: with --follow=name, reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or renamed (this is the usual case of rotated log files). With inotify, this option is rarely useful.
  • --pid=PID: with -f, terminate after process ID, PID dies
  • -q, --quiet, --silent: never output headers giving file names
  • --retry: keep trying to open a file even when it is or becomes inaccessible; useful when following by name, i.e., with --follow=name
  • -s, --sleep-interval=N: with -f, sleep for approximately N seconds (default 1.0) between iterations. With inotify and --pid=P, check process P at least once every N seconds.
  • -v, --verbose: always output headers giving file names
  • --help: display this help and exit
  • --version: output version information and exit.

NUM may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y. Binary prefixes can be used, too: KiB=K, MiB=M, and so on.

With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end. This default behavior is not desirable when you really want to track the actual name of the file, not the file descriptor (e.g., log rotation). Use --follow=name in that case. That causes tail to track the named file in a way that  ccommodates renaming, removal and creation.

Examples

Print the last 5 lines from a file
$ tail -n 5 HiC_K562_mapq30_1kb.0.1.bedpe 
chrX    155266000    155267000    chrX    155267000    155268000    1000    29    0.00000812823135226242    0.00144485134295292    2.06378184245937    2.48154751618014
chrX    155267000    155268000    chrX    155267000    155268000    0    26    0.0000339079266992884    0.00584509779601375    2.1141516989345    2.53194438387362
chrX    155268000    155269000    chrX    155269000    155270000    1000    23    0.0000934377296518742    0.0155829034826495    2.06418315453906    2.48194920420411
chrX    155269000    155270000    chrX    155270000    155270560    780    30    0.00000591103582516155    0.00105640998219185    2.08210298369456    2.49988315504676
chrX    155270000    155270560    chrX    155270000    155270560    0    19    0.000492303956519441    0.0706571936866273    2.07605646132443    2.49383244769862
Print a file and skip the first line

First let's take a look at the first 10 lines in the file

$ head HiC_K562_mapq30_1kb.0.1.bedpe 
chrI    startI    endI    chrJ    startJ    endJ    D    counts    pvalue    qvalue    mu    sdev
chr1    11000    12000    chr1    181000    182000    170000    11    0.00000000000189249582894287    0.000000000728621373580258    0.10886046714177    0.344173413371752
chr1    11000    12000    chr1    182000    183000    171000    16    0.00000000000000000749383947645951    0.0000000000000372986953510264    0.109184147690823    0.344726212693686
chr1    11000    12000    chr1    183000    184000    172000    6    0.000000382831510358736    0.000112052780188395    0.104632776141778    0.33689296272718
chr1    11000    12000    chr1    184000    185000    173000    6    0.000000343325951139647    0.000101357194386928    0.102588585875353    0.333331230570317
chr1    11000    12000    chr1    188000    189000    177000    3    0.000629451987116092    0.098743395042584    0.100726364855036    0.330062023979924
chr1    11000    12000    chr1    266000    267000    255000    3    0.000236048335626849    0.0492927435781896    0.0709233434931625    0.273853965197873
chr1    11000    12000    chr1    268000    269000    257000    4    0.0000100475655707419    0.00253286310439141    0.0655132012750288    0.262656075684313
chr1    11000    12000    chr1    271000    272000    260000    3    0.000169768235968914    0.0365970314014655    0.063143521982668    0.257627040108297
chr1    11000    12000    chr1    281000    282000    270000    3    0.000165617621285039    0.0357774010236488    0.0625967701651075    0.256455215154553

We can skip the first line by setting -n +2:

$ tail -n +2 HiC_K562_mapq30_1kb.0.1.bedpe | head
chr1    11000    12000    chr1    181000    182000    170000    11    0.00000000000189249582894287    0.000000000728621373580258    0.10886046714177    0.344173413371752
chr1    11000    12000    chr1    182000    183000    171000    16    0.00000000000000000749383947645951    0.0000000000000372986953510264    0.109184147690823    0.344726212693686
chr1    11000    12000    chr1    183000    184000    172000    6    0.000000382831510358736    0.000112052780188395    0.104632776141778    0.33689296272718
chr1    11000    12000    chr1    184000    185000    173000    6    0.000000343325951139647    0.000101357194386928    0.102588585875353    0.333331230570317
chr1    11000    12000    chr1    188000    189000    177000    3    0.000629451987116092    0.098743395042584    0.100726364855036    0.330062023979924
chr1    11000    12000    chr1    266000    267000    255000    3    0.000236048335626849    0.0492927435781896    0.0709233434931625    0.273853965197873
chr1    11000    12000    chr1    268000    269000    257000    4    0.0000100475655707419    0.00253286310439141    0.0655132012750288    0.262656075684313
chr1    11000    12000    chr1    271000    272000    260000    3    0.000169768235968914    0.0365970314014655    0.063143521982668    0.257627040108297
chr1    11000    12000    chr1    281000    282000    270000    3    0.000165617621285039    0.0357774010236488    0.0625967701651075    0.256455215154553
chr1    12000    13000    chr1    181000    182000    169000    5    0.00000465054509286984    0.00121532781933628    0.10429965391182    0.336314427652661


Share your experience or ask a question