tailx
Print the last part of each file, optionally following it as it grows.
Mirrors GNU tail. Run it as tailx, or as gnux tailx.
Synopsis
tailx [OPTION]... [FILE]...GNU reference
Description
tailx prints the last 10 lines of each FILE to standard output. With no FILE, or when FILE is -, it reads standard input. -n NUM changes the number of lines and -c NUM switches to bytes; a leading '+' on NUM starts output at line or byte NUM instead of counting from the end. NUM accepts a multiplier suffix: b is 512, K, M, G, T, P and E are powers of 1024 (also written KiB, MiB, ...), and KB, MB, ... are powers of 1000. With more than one FILE each is preceded by a '==> name <==' header; -q suppresses the headers and -v forces them. -f keeps running and prints data as it is appended, polling every -s seconds; --follow=name tracks the file name rather than the open file, so it survives log rotation, and --retry keeps waiting for a file that is missing. -F is shorthand for --follow=name --retry. --pid ends following when the given process exits. GNU tail, polling, checks whether a followed name has been rotated only after --max-unchanged-stats=N polls without growth (5 by default); tailx checks it on every poll, so it notices a rotation at once, and N is validated but changes nothing. On a regular file tailx seeks to the end and reads backward, so its cost does not depend on the file's size. On a terminal, gnux's terminal view colors the '==> FILE <==' headers in the theme's heading color; the text is GNU's, and piped or redirected output is never colored.
Permissions
Needs read permission on each FILE and search permission on the directories leading to it. Nothing is ever modified. With --follow=name the file is reopened on every poll, so permissions are re-checked as it is rotated.
Use cases
- Reading the most recent entries of a log.
- Watching a log live with
-f, or across rotations with-F. - Skipping a header with
-n+2. - Following a build log only for as long as the build runs, with
--pid. - Waiting for a log file that a service has not created yet, with
--retry. - Printing only new log lines from now on with
-n0-f. - Stripping a fixed-size prefix, such as a byte-order mark, with
-c+NUM. - Extracting a range of lines when combined with
headx. - Reading the last record of a NUL-separated list with
-z.
Flags
-c, --bytes [+]NUM output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file
-f, --follow HOW[="descriptor"] output appended data as the file grows; HOW is 'name' or 'descriptor' (the default)
-F, --follow-retry same as --follow=name --retry
--help display this help and exit
-n, --lines [+]NUM output the last NUM lines, instead of the last 10; or use -n +NUM to output 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 (default "5")
--pid PID with -f, terminate after process ID, PID, dies
--pretty WHEN[="always"] the gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default
-q, --quiet never output headers giving file names
--retry keep trying to open a file if it is inaccessible
--silent same as --quiet
-s, --sleep-interval N with -f, sleep for approximately N seconds (default 1.0) between iterations (default 1)
--theme NAME color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
-v, --verbose always output headers giving file names
--version output version information and exit
-z, --zero-terminated line delimiter is NUL, not newlineExamples
Print the last 10 lines of a file
tailx app.logPrint the last 50 lines
tailx -n 50 app.logPrint the last 3 lines, using the historical -NUM form
tailx -3 app.logPrint everything from the second line on (skip a header)
tailx -n +2 data.csvPrint the last 100 bytes of a file
tailx -c 100 app.logDrop a 3-byte UTF-8 byte-order mark by starting at byte 4
tailx -c +4 with-bom.txt > clean.txtPrint the last line of each log, with and without file name headers
tailx -n 1 a.log b.log && tailx -q -n 1 a.log b.logForce the header for a single file (--silent is the long spelling of -q)
tailx -v -n 5 app.logPrint lines 11 to 20 of a file
headx -n 20 app.log | tailx -n 10Print the oldest entry of a directory
lsx -t | tailx -n 1Print the last entry of a NUL-separated list
tailx -z -n 1 names.lst | xargs -0 echoxFollow a log, printing only lines appended from now on
tailx -n 0 -f app.logFollow a log across rotations, polling twice a second
tailx -F -s 0.5 /var/log/app.logFollow by name and wait for a file that does not exist yet
tailx --follow=name --retry service.logFollow a log until a process exits
make > build.log 2>&1 & tailx -f --pid=$! build.logReport a missing file through the exit status
tailx missing.log || echox "exit status $?"Show the end of every log in the portable gnux shell
gnux shell -c 'catx *.log | tailx -n 5'Options
Each option has a page of its own, with its usage and examples.
- -c, --bytes: Output the last NUM bytes; or use
-c+NUM to output starting with byte NUM of each file. - -f, --follow: Output appended data as the file grows; HOW is 'name' or 'descriptor' (the default).
- -F, --follow-retry: Same as
--follow=name--retry. - -n, --lines: Output the last NUM lines, instead of the last 10; or use
-n+NUM to output starting with line NUM. - --max-unchanged-stats: 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. - --pid: With
-f, terminate after process ID, PID, dies. - --pretty: The
gnuxterminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default. - -q, --quiet: Never output headers giving file names.
- --retry: Keep trying to open a file if it is inaccessible.
- --silent: Same as
--quiet. - -s, --sleep-interval: With
-f, sleep for approximately N seconds (default 1.0) between iterations. - --theme: Color the view with the built-in theme NAME (
gnuxtheme picks and saves one); GNUX_THEME sets the default. - -v, --verbose: Always output headers giving file names.
- -z, --zero-terminated: Line delimiter is NUL, not newline.
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake |
Help in the terminal
tailx --help # options, first examples, exit status
gnux help tailx # this page: the full manual
gnux help tailx --OPTION # one option in depth, with its examples