为什么“ head -1”不等同于“ head -n -1”,而是与“ head -n 1”相同?

用户名

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还支持过时的选项语法-[NUM][bkm][cqv],只有先指定该语法才能识别该语法

有观点认为,head -1相同head -n 1的是,破折号不是减号,但对于一个命令行选项标记。这是通常的习惯:以破折号开头的是控制处理方式的选项,命令行中的其他内容是文件名或要处理的其他实际目标。在这种情况下,它不是单字符选项,而是的简写形式-n,但基本上还是一个选项,而不是文件名。head +1或中head 1将以+11作为文件名。

双破折号----something也有不同的含义,就其本身(--)而言,它会停止选项处理,而在后面加上其他内容时,它会标记一个GNU风格的长选项。因此,head --1forhead -n -1不会符合该习俗。

如果我猜到了,我会假设存在一个古怪的捷径可以肯定,但不能否定,因为前一种情况更有用且更容易实现。(此外,该标准仅针对线的正值进行定义。)-n iiihead

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

linux中的“ ls -t | head -n 1”是做什么的?

HEAD 和 HEAD~1 有什么区别?

为什么`seq 100 | (head -n1; tail -n1)`是否可以在Mac OSX上使用?

b/w 'git diff HEAD' 与 'git diff HEAD HEAD~1' 有什么区别?

“ ListNode虚拟{-1,head};”是什么?意思是?

为什么git reset'HEAD @ {1}'抛出错误?

在 Scrapy 中,为什么 Xpath 表达式中的 text()[n] 后跟 extract() 不等同于 extract() 然后选择第 [n-1] 个元素?

Git结帐HEAD + 1和HEAD-1

Cocoapods':head'等同于Mercurial

Windows等同于'head -c'命令的

如何找出HEAD-0,HEAD-1等是哪个屏幕?

HEAD~n^k 在 git 上做什么?

为什么 git HEAD~[N] 只指拉请求?

git中的“ HEAD〜1”之类的指针的名称是什么?

`git rebase -i HEAD~N` 和 `git reset --soft HEAD~N` 有什么区别?

如何撤消`git reset --hard HEAD〜1`?

如何撤消git reset --hard HEAD〜1?

HEAD在sha1分离

git reset --hard HEAD〜1和git reset HEAD〜1 --hard之间的区别?

执行http请求时出错:未定义:1 <head> <title>文档已移动</ title> </ head>

在if条件下使用head -n

什么是Git HEAD @ {x}

git reset HEAD @ {1}是否不删除已添加的文件?

使用子过程获取通过head -1传递的grep输出

Shell脚本错误:“ head:无效的尾随选项-1”

Git:HEAD与Head

groupby.first()和groupby.head(1)有什么区别?

有什么办法可以读取int 13h放在head = 1上的内核?

python3-从文本文件格式head1 = value | head2 = value导入数据框