Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 正面的否定论点_Linux_Macos_Zsh_Tail_Head - Fatal编程技术网

Linux 正面的否定论点

Linux 正面的否定论点,linux,macos,zsh,tail,head,Linux,Macos,Zsh,Tail,Head,我试着使用head命令,在macOS中使用zsh,代码如下 a.txt: 1 2 3 4 5 6 7 8 9 10 tail -n +5 a.txt // line 5 to line end tail -n -5 a.txt // last line 5 to line end head -n +5 a.txt // line 1 to line 5 head -n -5 a.txt // # What did this do? 最后一个命令显示错误 head: ill

我试着使用
head
命令,在macOS中使用zsh,代码如下

a.txt:

1
2
3
4
5
6
7
8
9
10

tail -n +5 a.txt   // line 5 to line end

tail -n -5 a.txt   // last line 5 to line end

head -n +5 a.txt // line 1 to line 5

head -n -5 a.txt  // # What did this do?

最后一个命令显示错误

head: illegal line count -- -5

head-n-5实际上做了什么?

如果使用
3
而不是
5
,情况会变得更清楚。注意这些迹象

# print 10 lines:
seq 10

1
2
3
4
5
6
7
8
9
10

#-------------------------    
# get the last 3 lines:
seq 10 | tail -n 3

8
9
10

#--------------------------------------
# start at line 3 (skip first 2 lines)
seq 10 | tail -n +3

3
4
5
6
7
8
9
10

#-------------------------    
# get the first 3 lines:
seq 10 | head -n 3

1
2
3

#-------------------------    
# skip the last 3 lines:
seq 10 | head -n -3

1
2
3
4
5
6
7
顺便说一句,
mantail
manhead
解释了这种行为。

一些
head
的实现,如GNU
head
支持
-n

但这不是标准您的案例显然不受支持。


受支持时在执行
头部
之前,否定参数应删除最后的
5行

头部
应回答您的所有问题。显示了什么错误?你试过阅读吗?@Someprogrammerdude嗨,我加了一个错误看这个@RobbyCornelissen它没有,因为Mac电脑上的
人头
根本不显示任何信息,尽管
信息人头
显示,但它仍然显示有效的否定
-n
标志,这是macOs不支持的。因此,问题是有效的,答案不在手册中:)