Modular Computers the manual GitHub

tail

tail: output the last part of files.

Synopsis

tail [-f] [-n [+]lines] [-c [+]bytes] [file…]

Description

tail writes the last 10 lines of each file to standard output. With no file, or for a file named -, it reads standard input. With more than one file, each is headed by ==> name <== (standard input is named standard input), with a blank line before every heading but the first.

Options

-f
Follows: once the files are shown, waits, and shows what is added to them, until it’s stopped (^C, or kill). Everything is shown the moment it comes: files on a disk or in /tmp are watched (inotify: a disk reports each change made on it), and pipes and device files are waited on with poll, all together. A file rewritten rather than added to (a disk file grown shorter, or a device whose state changed, as a redstone card’s) is shown again from its start, after tail: file: file truncated on standard error. A heading names the file when the text is another file’s than the last shown. Standard input isn’t followed. A device file is read only as far as it has something now, so one that never ends (a motion sensor’s: an event a line) shows the last of the events waiting, then each as it comes.
-n lines
The last lines lines. +lines starts at line lines instead (1 is the first), and goes on to the end.
-c bytes
The last bytes bytes; +bytes starts at that byte and goes on to the end.
-number
The same as -n number.

The number may be joined to its option (-n5) or follow it as the next argument. A later -n undoes an earlier -c.

Exit status

0 on success; 1 if a number or an option is invalid, or a file can’t be opened (the other files are still shown).

Examples

tail -n 3 /init.lua
tail -n +2 list.txt
ps | tail -c 100
tail -f /dev/redstone0
tail -f /dev/motion0

Notes

What another program writes to a file on a disk shows when it closes the file (a disk’s files take writes at close), so tail -f sees a line once its writer has closed the file; >> in the shell closes it at once. GNU tail reads a device’s file to its end first, so on one that never ends (a sensor’s events) it shows nothing; with -f, this one reads only what the device has now, then follows it. A change made to a disk’s file outside the computer (on the disk’s host) isn’t seen until the next change made inside it.

See also

head(1), cat(1), grep(1)