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
的实现,如GNUhead
支持-n
但这不是标准您的案例显然不受支持。
受支持时在执行
头部
之前,否定参数应删除最后的5行
头部
应回答您的所有问题。显示了什么错误?你试过阅读吗?@Someprogrammerdude嗨,我加了一个错误看这个@RobbyCornelissen它没有,因为Mac电脑上的人头
根本不显示任何信息,尽管信息人头
显示,但它仍然显示有效的否定-n
标志,这是macOs不支持的。因此,问题是有效的,答案不在手册中:)