[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These commands output pieces of the input.
5.1 head
: Output the first part of filesOutput the first part of files. 5.2 tail
: Output the last part of filesOutput the last part of files. 5.3 split
: Split a file into fixed-size piecesSplit a file into fixed-size pieces. 5.4 csplit
: Split a file into context-determined piecesSplit a file into context-determined pieces.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
head
: Output the first part of files
head
prints the first part (10 lines by default) of each
file; it reads from standard input if no files are given or
when given a file of `-'. Synopses:
head [option]... [file]... head -number [option]... [file]... |
If more than one file is specified, head
prints a
one-line header consisting of
==> file name <== |
head
accepts two option formats: the new one, in which numbers
are arguments to the options (`-q -n 1'), and the old one, in which
the number precedes any option letters (`-1q').
The program accepts the following options. Also see 2. Common options.
-c
, or `l' to mean count by lines,
or other option letters (`cqv').
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tail
: Output the last part of files
tail
prints the last part (10 lines by default) of each
file; it reads from standard input if no files are given or
when given a file of `-'. Synopses:
tail [option]... [file]... tail -number [option]... [file]... tail +number [option]... [file]... |
If more than one file is specified, tail
prints a
one-line header consisting of
==> file name <== |
GNU tail
can output any amount of data (some other versions of
tail
cannot). It also has no `-r' option (print in
reverse), since reversing a file is really a different job from printing
the end of a file; BSD tail
(which is the one with -r
) can
only reverse files that are at most as large as its buffer, which is
typically 32k. A more reliable and versatile way to reverse files is
the GNU tac
command.
tail
accepts two option formats: the new one, in which numbers
are arguments to the options (`-n 1'), and the old one, in which
the number precedes any option letters (`-1' or `+1').
If any option-argument is a number n starting with a `+',
tail
begins printing with the nth item from the start of
each file, instead of from the end.
The program accepts the following options. Also see 2. Common options.
-c
, or `l' to mean count by lines,
or other option letters (`cfqv').
tail
prints a header whenever it
gets output from a different file, to indicate which file that output is
from.
There are two ways to specify how you'd like to track files with this option, but that difference is noticeable only when a followed file is removed or renamed. If you'd like to continue to track the end of a growing file even after it has been unlinked, use `--follow=descriptor'. This is the default behavior, but it is not useful if you're tracking a log file that may be rotated (removed or renamed, then reopened). In that case, use `--follow=name' to track the named file by reopening it periodically to see if it has been removed and recreated by some other program.
No matter which method you use, if the tracked file is determined to have
shrunk, tail
prints a message saying the file has been truncated
and resumes tracking the end of the file from the newly-determined endpoint.
When a file is removed, tail
's behavior depends on whether it is
following the name or the descriptor. When following by name, tail can
detect that a file has been removed and gives a message to that effect,
and if `--retry' has been specified it will continue checking
periodically to see if the file reappears.
When following a descriptor, tail does not detect that the file has
been unlinked or renamed and issues no message; even though the file
may no longer be accessible via its original name, it may still be
growing.
The option values `descriptor' and `name' may be specified only with the long form of the option, not with `-f'.
make
and tail
like this then the tail process will stop when your build completes.
Without this option, you would have had to kill the tail -f
process yourself.
$ make >& makerr & tail --pid=$! -f makerr |
tail
may terminate long before any files stop growing or it may not
terminate until long after the real writer has terminated.
tail
follows the descriptor of a file
that continues growing at a rapid pace even after it is deleted or renamed.
After detecting n consecutive size changes for a file,
open
/fstat
the file to determine if that file name is
still associated with the same device/inode-number pair as before.
See the output of tail --help
for the default value.
open
/fstat
the file to determine if that file name is
still associated with the same device/inode-number pair as before.
When following a log file that is rotated this is approximately the
number of seconds between when tail prints the last pre-rotation lines
and when it prints the lines that have accumulated in the new log file.
See the output of tail --help
for the default value.
This option is meaningful only when following by name.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
split
: Split a file into fixed-size pieces
split
creates output files containing consecutive sections of
input (standard input if none is given or input is
`-'). Synopsis:
split [option] [input [prefix]] |
By default, split
puts 1000 lines of input (or whatever is
left over for the last section), into each output file.
The output files' names consist of prefix (`x' by default)
followed by a group of letters `aa', `ab', and so on, such
that concatenating the output files in sorted order by file name produces
the original input file. (If more than 676 output files are required,
split
uses `zaa', `zab', etc.)
The program accepts the following options. Also see 2. Common options.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
csplit
: Split a file into context-determined pieces
csplit
creates zero or more output files containing sections of
input (standard input if input is `-'). Synopsis:
csplit [option]... input pattern... |
The contents of the output files are determined by the pattern arguments, as detailed below. An error occurs if a pattern argument refers to a nonexistent line of the input file (e.g., if no remaining line matches a given regular expression). After every pattern has been matched, any remaining input is copied into one last output file.
By default, csplit
prints the number of bytes written to each
output file after it has been created.
The types of pattern arguments are:
The output files' names consist of a prefix (`xx' by default) followed by a suffix. By default, the suffix is an ascending sequence of two-digit decimal numbers from `00' and up to `99'. In any case, concatenating the output files in sorted order by filename produces the original input file.
By default, if csplit
encounters an error or receives a hangup,
interrupt, quit, or terminate signal, it removes any output files
that it has created so far before it exits.
The program accepts the following options. Also see 2. Common options.
printf(3)
-style conversion specification, possibly including
format specification flags, a field width, a precision specifications,
or all of these kinds of modifiers. The format letter must convert a
binary integer argument to readable form; thus, only `d', `i',
`u', `o', `x', and `X' conversions are allowed. The
entire suffix is given (with the current output file number) to
sprintf(3)
to form the file name suffixes for each of the
individual output files in turn. If this option is used, the
`--digits' option is ignored.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |