Documentation
¶
Overview ¶
Package head implements the head builtin command.
head — output the first part of files
Usage: head [OPTION]... [FILE]...
Print the first 10 lines 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.
Accepted flags:
-n N, --lines=N
Output the first N lines (default 10). A leading '+' (e.g. +5) is
treated as a positive sign and is equivalent to plain 5.
-c N, --bytes=N
Output the first N bytes instead of lines. A leading '+' is treated
as a positive sign. If both -n and -c are specified, the last flag
on the command line takes effect.
-q, --quiet, --silent
Never print file name headers. --silent is an alias for --quiet.
-v, --verbose
Always print file name headers, even when only one file is given.
-h, --help
Print this usage message to stdout and exit 0.
Exit codes:
0 All files processed successfully. 1 At least one error occurred (missing file, invalid argument, etc.).
Memory safety:
Line mode uses a streaming scanner with a per-line cap of MaxLineBytes (1 MiB). Lines that exceed this cap cause an error rather than an unbounded allocation. Byte mode reads in fixed-size chunks; it never allocates proportionally to user-supplied N. All loops check ctx.Err() at each iteration to honour the shell's execution timeout and to support graceful cancellation.
Index ¶
Constants ¶
const MaxCount = 1<<31 - 1 // 2 147 483 647
MaxCount is the maximum accepted line or byte count. Values above this are clamped. This prevents huge theoretical allocations while remaining larger than any practical file.
const MaxLineBytes = 1 << 20 // 1 MiB
MaxLineBytes is the per-line buffer cap for the line scanner. Lines longer than this are reported as an error instead of being buffered.
Variables ¶
var Cmd = builtins.Command{
Name: "head",
Description: "output the first part of files",
MakeFlags: registerFlags,
}
Cmd is the head builtin command descriptor.
Functions ¶
This section is empty.
Types ¶
This section is empty.