Linux命令总结—head命令
(1)命令功能
head命令用于显示文件的开关的内容。在默认情况下,head命令显示文件的头10行内容。
(2)命令语法
head(选项) (参数)
(3)选项说明
- -n <数字>:指定显示头部内容的行数;
- -c <字符数>:指定显示头部内容的字符数;
- -v:总是显示文件名的头信息,显示多个文件时默认选项;
- -q:不显示文件名的头信息,显示单个文件时默认选项;
(4)参数说明
- 文件列表:指定显示头部内容的文件列表。
(5)实例
实例1:显示单个文件的头部内容—head文件
[[email protected] ~]#head /etc/inittab # inittab is onlyused by upstart for the default runlevel. # # ADDING OTHERCONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Systeminitialization is started by /etc/init/rcS.conf # # Individual runlevelsare started by /etc/init/rc.conf # # Ctrl-Alt-Delete ishandled by /etc/init/control-alt-delete.conf #
实例2:显示多个文件的头部内容—head 文件 文件
[[email protected] ~]# head /etc/inittab /etc/fstab ==> /etc/inittab <== # inittab is only used by upstart for the defaultrunlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ONYOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by/etc/init/control-alt-delete.conf # ==> /etc/fstab <== # # /etc/fstab # Created by anaconda on Mon May 11 22:18:51 2015 # # Accessible filesystems, by reference, are maintainedunder ‘/dev/disk‘ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8)for more info # UUID=17ec9366-d335-4b07-8890-3765cabe746a / ext4 defaults 1 1 UUID=1f8e61c7-de21-42e3-89c5-cb28f607d1db /boot ext4 defaults 1 2
实例3:显示文件头部指定行数的内容—head –n <行数>
[[email protected] ~]# head -n 5 /etc/inittab # inittab is onlyused by upstart for the default runlevel. # # ADDING OTHERCONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Systeminitialization is started by /etc/init/rcS.conf
实例4:显示文件头部指定字符数的内容—head –c <字符数>
[[email protected] ~]# head -c 88 /etc/inittab # inittab is onlyused by upstart for the default runlevel. # # ADDING OTHERCONFIGURATI[[email protected] ~]#
时间: 2024-10-21 12:58:51