Linux 命令head是什么作用 ls|sort|head -2 这个命令语句是用来做什么的?

linux sh\u811a\u672c\u4e2d<<< HEAD\u662f\u4ec0\u4e48\u7528\u9014

\u53ea\u542c\u8bf4\u8fc7\u4e24\u4e2a\u5c0f\u4e8e\u53f7\u8fd9\u79cd
<<HEAD
\u8fd9\u53ebHere Document,\u8868\u793a\u4ece\u547d\u4ee4\u884c\u63a5\u53d7\u8f93\u5165\uff0c\u76f4\u5230\u5728\u67d0\u884c\u8f93\u5165\u76f8\u540c\u7684\u5355\u8bcdHEAD\u7ed3\u675f\u8f93\u5165
<<<HEAD\u4e09\u4e2a\u5c0f\u4e8e\u53f7\u7684\u6ca1\u542c\u8bf4\u8fc7

\u8fd9\u4e2a\u662fUnix(Linux)\u4e0b\u7684\u4e00\u4e2a\u547d\u4ee4\u4e32\u3002
ls\u662f\u5217\u51fa\u6587\u4ef6\u7684\u610f\u601d
sort\u662f\u5bf9\u8f93\u5165\u6570\u636e\u884c\u6392\u5e8f\u7684\u610f\u601d
head \u662f\u4ece\u8f93\u5165\u6587\u4ef6\u5934\u90e8\u8bfb\u53d6\u7684\u610f\u601d\uff0c -2\u662f\u8fd9\u4e2a\u547d\u4ee4\u7684\u53c2\u6570\u3002
\u6211\u628a\u628a\u8fd9\u4e2a\u547d\u4ee4\u4e32\u5728\u6211\u7684\u7cfb\u7edf\u4e0a\u6267\u884c\uff0c\u5176\u7ed3\u679c\u5982\u4e0b\uff1a

[android@android ~]$ ls
alg install_flash_player_11_linux.i386 repo02
android-sdk-linux Music share
bin objc Templates
Desktop Pictures Videos
Documents Public workspace
Downloads remote-repository.git
froyo repo01
[android@android ~]$ ls |sort|head -2
alg
android-sdk-linux
[android@android ~]$

从文件的头部开始,显示文件的前几行。

默认是前10行,显示的行数可以通过参数 -n 指定。

显示文件的最前面的行,可以带参数数字,默认显示前10行。

显示文件的前面行数。通常使用head -n filename。比如head -n 3 /etc/fstab 显示/etc/fstab文件的前三行。可以和tail连用来显示特定的行。head -n 3 /etc/fstab | tail -n 1 显示/etc/fstab的第三行

head功能:用于显示文件前几行的内容

格式:head[参数]

[root@linux root]# head -10 /etc/passwd 显示/etc/passwd/文件的前10行内容

1、head file 默认显示文件头10行2、head -5 file 显示文件头5行

扩展阅读:linux中head和tail的用法 ... route add 全部命令 ... linux的less命令详解 ... linux more命令 ... linux head命令详解 ... linux wc命令 ... 《linux命令行大全》 ... linux挂载命令mount ... linux中tail命令 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网