tail: Display the last part of a file

Format

tail [-B] [-f] [-W option[option] ... [-b|-c|-k|-l|-m|-n [±]number] [file]

tail [-B] [-W option[option] ... ±[number][b|c|k|l|m|n][f] [file]

Description

tail without options displays the The display is useful for seeing the most recent entries in log files and any file where new information is added on the end.

The tail command is used with text files. To make a binary file input to the tail command, use the –c option. If a binary file is input without the -c option being specified, the entire file is sent to the screen.

If you do not specify a file, or if you specify - as the file name, tail reads from the standard input (stdin).

Options

+-number
Is either of the following:
+number
Skips to line number and then displays the rest of the file. For example, +100 prints from line 100 to the end of the file.
-number
Prints number lines from the end of the file. For example, -20 prints the last 20 lines in the file.
You can precede or follow both +number and number with one of the following letters to indicate the unit to be used:
  • b-blocks
  • c-bytes
  • k-kilobytes
  • l or n-lines
  • m-megabytes

The default unit is lines.

-B
Disables the automatic conversion of tagged files. This option is ignored if the filecodeset or pgmcodeset options (-W option) are specified.
-f
Monitors a file as it grows. Every two seconds, tail wakes up and prints any new data at the end of the file. This option is ignored if tail read from the standard input, and standard input is a pipe.
-W option[,option]...
Specifies z/OS-specific options. The option keywords are case-sensitive. Possible options are:
filecodeset=codeset
Performs text conversion from one code set to another when reading from the file. The coded character set of the file is codeset. codeset can be a code set name that is known to the system or a numeric coded character set identifier (CCSID). Note that the command iconv -l lists existing CCSIDs along with their corresponding code set names. The filecodeset and pgmcodeset options can be used on files with any file tag.

If pgmcodeset is specified but filecodeset is omitted, then the default file code set is ISO8859-1 even if the file is tagged with a different code set. If neither filecodeset nor pgmcodeset is specified, text conversion will not occur unless automatic conversion is enabled or the _TEXT_CONV environment variable indicates text conversion. For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.

If filecodeset or pgmcodeset is specified, then automatic conversion is disabled for this command invocation and the -B option is ignored if it is also specified. See z/OS UNIX System Services Planning for more information about automatic conversion.

When specifying values for filecodeset, use the values that Unicode Service supports. For more information about supported code sets, see z/OS Unicode Services User's Guide and Reference.

pgmcodeset=codeset
Performs text conversion from one code set to another when reading from the file. The coded character set of the program (command) is codeset. codeset can be a code set name that is known to the system or a numeric coded character set identifier (CCSID). Note that the command iconv -l lists existing CCSIDs along with their corresponding code set names. The filecodeset and pgmcodeset options can be used on files with any file tag.

If filecodeset is specified but pgmcodeset is omitted, then the default program code set is IBM-1047. If neither filecodeset nor pgmcodeset is specified, text conversion will not occur unless automatic conversion is enabled or the _TEXT_CONV environment variable indicates text conversion. For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.

If filecodeset or pgmcodeset is specified, then automatic conversion is disabled for this command invocation and the -B option is ignored if it is also specified. See z/OS UNIX System Services Planning for more information about automatic conversion.

The only supported values for pgmcodeset are IBM-1047 and 1047.

Examples

  1. To display the last 10 lines of a text file to the standard output (stdout):
    tail myTextFile
  2. To display the last line of a text file and then monitor the file for updates (display new data that is written to the text file):
    tail -f -n -1  myTextFile
  3. To display the last 200 bytes of a text file containing UTF-8 characters to the standard output (stdout), assuming that:
    • The text file is untagged and you do not want to tag it or enable automatic conversion, and
    • You cannot alter the tag (for example, you are displaying an untagged public text file or a read-only text file):
      tail -W filecodeset=UTF-8,pgmcodeset=IBM-1047 -c -200 myUtf8File
  4. To display a text file containing EBCDIC characters starting at line 25, assuming that automatic conversion has been enabled but the text file is incorrectly tagged as ASCII:
    tail -B -n +25 myMisTaggedFile

Localization

tail uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • NLSPATH

See Localization for more information.

Environment variables

tail uses the following environment variable:
_TEXT_CONV
Contains text conversion information for the command. The text conversion information is not used when either the -B option or the filecodeset or pgmcodeset option (-W option) is specified. For more information about text conversion, see Controlling text conversion for z/OS UNIX shell commands.

Exit values

0
Successful completion
1
Failure due to any of the following reasons:
  • Insufficient memory.
  • Write error on the standard output (stout).
  • Badly formed line or character count.
  • Missing number after an option.
  • Error reopening a file descriptor.
  • The code set is not valid.
  • Could not turn off automatic conversion.
  • Could not perform requested text conversion.n
2
Failure due to an unknown command-line option.

Messages

Possible error messages include:
Badly formed line/character count string
In an option of the form –n number or number, the number was not a valid number.
Reopening file descriptor number
–f was used to follow a file as it grew. tail closed the file that is associated with the given file descriptor number and then tried to open it 2 seconds later. At this point, tail found it could not reopen the file for reading, and therefore could not follow the file any longer.

Portability

POSIX.2, X/Open Portability Guide, UNIX systems.

The POSIX standard included only the -f, -c+ -number, and -n±number options. The use of b, c and l as a + -number suffix is considered obsolete. All other options and suffixes are extensions of the POSIX standard.

Related information

cat, head, more