head -num
head -n num
与而不是相同head -n -num
(其中num
是任何数字)
例子:
$ echo -e 'a\nb\nc\nd'|head -1
a
$ echo -e 'a\nb\nc\nd'|head -n 1
a
$ echo -e 'a\nb\nc\nd'|head -n -1
a
b
c
这head -1
似乎没有记录在任何地方。
$ head --help
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.
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=[-]NUM print the first NUM bytes of each file;
with the leading '-', print all but the last
NUM bytes of each file
-n, --lines=[-]NUM print the first NUM lines instead of the first 10;
with the leading '-', print all but the last
NUM lines of each file
-q, --quiet, --silent never print headers giving file names
-v, --verbose always print headers giving file names
-z, --zero-terminated line delimiter is NUL, not newline
--help display this help and exit
--version output version information and exit
NUM may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/head>
or available locally via: info '(coreutils) head invocation'
head
(在 Fedora 28 上) 的手册页:
HEAD(1) User Commands HEAD(1)
NAME
head - output the first part of files
SYNOPSIS
head [OPTION]... [FILE]...
DESCRIPTION
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.
Mandatory arguments to long options are mandatory for short options
too.
-c, --bytes=[-]NUM
print the first NUM bytes of each file; with the leading '-',
print all but the last NUM bytes of each file
-n, --lines=[-]NUM
print the first NUM lines instead of the first 10; with the
leading '-', print all but the last NUM lines of each file
-q, --quiet, --silent
never print headers giving file names
-v, --verbose
always print headers giving file names
-z, --zero-terminated
line delimiter is NUL, not newline
--help display this help and exit
--version
output version information and exit
NUM may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000,
M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P,
E, Z, Y.
AUTHOR
Written by David MacKenzie and Jim Meyering.
REPORTING BUGS
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report head translation bugs to <https://translationproject.org/team/>
COPYRIGHT
Copyright © 2017 Free Software Foundation, Inc. License GPLv3+: GNU
GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
tail(1)
Full documentation at: <https://www.gnu.org/software/coreutils/head>
or available locally via: info '(coreutils) head invocation'
GNU coreutils 8.29 December 2017 HEAD(1)
GNU的信息页面和在线手册
head
包含以下部分:head -1
与此相同的想法是head -n 1
破折号不是减号,而是命令行选项的标记。这是通常的习惯:以破折号开头的东西是控制如何进行处理的选项,命令行中的其他东西是文件名或其他要处理的实际目标。在这种情况下,它不是单字符选项,而是 的简写-n
,但它基本上仍然是一个选项,而不是文件名。但是,在head +1
orhead 1
中,+1
or1
将被视为文件名。双破折号
--
或--something
也有不同的含义,它本身 (--
) 它停止选项处理,当后面跟着其他东西时,它标志着一个 GNU 风格的长选项。因此,拥有head --1
forhead -n -1
与习俗不符。如果我猜的话,我会假设存在的古朴快捷方式是积极的,而不是消极的,因为前一种情况更经常有用并且更容易实现。(此外,该标准仅针对线的正值定义。)
-n i
i
i
head