head命令用于显示文件的开头的内容。在默认情况下,head命令显示文件的头10行内容。
    如果指定了多于一个文件,在每一段输出前会给出文件名作为文件头。

如果不指定文件,或者文件为"-",则从标准输入读取数据。

    (1)用法:

用法: head [选项]... [文件]...

    (2)功能:

将每个指定文件的头10 行显示到标准输出。

    (3)选项参数:

1)-q             隐藏文件名

2)-v             显示文件名

3)-c<字节>          显示字节数

4)-n<行数>          显示的行数

    (4)实例:

1)[root@localhost Documents]# head head_text            默认显示文件的前10行

[root@localhost Documents]# ll
总用量
-rw-r--r--. root root 5月 : head_text
-rw-r--r--. root root 5月 : less1
-rw-r--r--. root root 5月 : less2
[root@localhost Documents]# head head_text
I am studing orders of Linux!
I am trying to write as many as lines of text! No matter how low you consider yourself,
there is always someone looking behind you,
hoping that they were that high! Something you want keep all the time,always you will lose!

2)[root@localhost Documents]# head -5 head_text  与    [root@localhost Documents]# head -n 5 head_text             相同的功能:自定义显示文件前5行

[root@localhost Documents]# head - head_text
I am studing orders of Linux!
I am trying to write as many as lines of text! No matter how low you consider yourself,
[root@localhost Documents]# head -n head_text
I am studing orders of Linux!
I am trying to write as many as lines of text! No matter how low you consider yourself,

3)[root@localhost Documents]# head -c 20 head_text           指定自定义显示前20个字节的内容

[root@localhost Documents]# head -c  head_text
I am studing orders [root@localhost Documents]#
[root@localhost Documents]# head -c head_text
I am studing orders of Linux!
I am trying to write as many a

4)[root@localhost Documents]# head -c -50 head_text           指定除末尾的50个字节外全部显示

[root@localhost Documents]# head -c - head_text
I am studing orders of Linux!
I am trying to write as many as lines of text! No matter how low you consider yourself,
there is always someone looking behind you,
hoping that they were that high! Something you want keep all the time,always you will lose! Never forget to say "thanks"! Hppay today,also,prepared for happiness in the future! Don't aim your success if you want it,just do what you love and believe and finally you will success! Maybe you can be laze man like a pig,but you can't feel free as it! I am a college school student!
I am planning to live and work in hangzhou or guangzhou!
I am from[root@localhost Documents]#

5)I am from[root@localhost Documents]# head -n -10 head_text                    除最后10行外全部显示

I am from[root@localhost Documents]# head -n - head_text
I am studing orders of Linux!
I am trying to write as many as lines of text! No matter how low you consider yourself,
there is always someone looking behind you,
hoping that they were that high! Something you want keep all the time,always you will lose! Never forget to say "thanks"! [root@localhost Documents]#

6)[root@localhost Documents]# head -v less1 less2                                     显示多个文件,并且在显示前打印出每个文件的文件名

[root@localhost Documents]# head -v  less1 less2
==> less1 <==
Lost means Get! No losing No getting! End! ==> less2 <==
If you want keep,you always lose! Certainly It is!
End!

-v参数是默认的,即是不加也会如此:

[root@localhost Documents]# head less1 less2
==> less1 <==
Lost means Get! No losing No getting! End! ==> less2 <==
If you want keep,you always lose! Certainly It is!
End!

7)[root@localhost Documents]# head -q -n 3 less1 less2 head_text              -q参数用来指定显示多个文件,不加文件名。同时也可以用-n 10指定只显示前3行

[root@localhost Documents]# head -q -n  less1 less2 head_text
Lost means Get! No losing No getting!
If you want keep,you always lose! Certainly It is!
I am studing orders of Linux!
I am trying to write as many as lines of text! [root@localhost Documents]#

8)[root@localhost Documents]# head --help

[root@localhost Documents]# head --help
用法:head [选项]... [文件]...
Print the first 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=[-]K print the first K bytes of each file;
with the leading '-', print all but the last
K bytes of each file
-n, --lines=[-]K print the first K lines instead of the first ;
with the leading '-', print all but the last
K lines of each file
-q, --quiet, --silent 不显示包含给定文件名的文件头
-v, --verbose 总是显示包含给定文件名的文件头
--help 显示此帮助信息并退出
--version 显示版本信息并退出 K 后面可以跟乘号:
b , kB , K , MB *, M *,
GB **, G **, 对于T, P, E, Z, Y 同样适用。 GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告head 的翻译错误
要获取完整文档,请运行:info coreutils 'head invocation'

9)[root@localhost Documents]# head --version

[root@localhost Documents]# head --version
head (GNU coreutils) 8.22
Copyright (C) Free Software Foundation, Inc.
许可证:GPLv3+:GNU 通用公共许可证第3 版或更新版本<http://gnu.org/licenses/gpl.html>。
本软件是自由软件:您可以自由修改和重新发布它。
在法律范围内没有其他保证。 由David MacKenzie 和Jim Meyering 编写。

每天一个Linux命令(14)head命令的更多相关文章

  1. linux常用命令(14)which命令

    我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索:    which  查看可执行文件的位置.   whereis 查看文件的位置.    locate   配合数 ...

  2. 每天一个linux命令(14):head命令

    1.命令简介 head (head) 用来显示档案的开头至标准输出中.如果指定了多于一个文件,在每一段输出前会给出文件名作为文件头.如果不指定文件,或者文件为"-",则从标准输入读 ...

  3. Redis 的键命令、HyperLogLog 命令、脚本命令、连接命令、服务器命令

    Redis 的键命令.HyperLogLog 命令.脚本命令.连接命令.服务器命令 Redis 的键命令 Redis 的键命令主要用于管理 Redis 的键,如删除键.查询键.修改键及设置某个键等. ...

  4. 每天一个linux命令:less(14)

    less less命令的作用与more十分相似,都可以用来浏览文字档案的内容,less 在查看之前不会加载整个文件 .用less命令显示文件时,用PageUp键向上翻页,用PageDown键向下翻页. ...

  5. 每天一个linux命令(14):less命令

    版权声明更新:2017-05-18博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下面的mv命令. 2. ...

  6. 每天一个 Linux 命令(21):find命令之xargs

    在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出 ...

  7. 每天一个linux命令(25):linux文件属性详解

    Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.具体情况如下: 命令: ls -lih 输出: [root@loca ...

  8. 每天一个linux命令(46):vmstat命令

    vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深 ...

  9. 每天一个linux命令目录

    出处:http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html 开始详细系统的学习linux常用命令,坚持每天一个命令,所以这个系列为每 ...

  10. 每天一个 Linux 命令(20):find命令之exec

    find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec  参数后面跟的是command ...

随机推荐

  1. appium for mac 安装与测试ios说明

    一.安装 安装dmg,可以自己下载appium-1.4.0.dmg或者找rtx我要,文件过大不能添加附件. Appium提供了一个doctor,运行appium-doctor 如果有问题,Fix it ...

  2. sql server 类oracle vm_contact() 函数创建

    CREATE FUNCTION dbo.fun_orgname(@id int)RETURNS varchar(8000)AS BEGIN      DECLARE @str varchar(8000 ...

  3. ubuntu 14.04 anaconda安装

    Python的准备工作 Python 一个备受欢迎的点是社区支持很多,有非常多优秀的库或者模块.但是某些库之间有时候也存在依赖,所以要安装这些库也是挺繁琐的过程.但总有人忍受不了这种 繁琐,都会开发出 ...

  4. LinkedList add remove get 代码分析

    add void linkLast(E e) { //e 要添加的元素 final Node<E> l = last; // 最后一个元素 final Node<E> newN ...

  5. VSCode调试.net core 2.0 输出窗口乱码

    Q:输出窗口乱码 A:修改.vscode文件夹下,tasks.json文件,具体内容见图

  6. 并行归并排序——MPI

    并行归并排序在程序开始时,会将n/comm_comm个键值分配给每个进程,程序结束时,所有的键值会按顺序存储在进程0中.为了做到这点,它使用了树形结构通信模式.当进程接收到另一个进程的键值时,它将该键 ...

  7. Android蓝牙通信具体解释

    蓝牙通信的大概过程例如以下: 1.首先开启蓝牙 2,搜索可用设备 3,创建蓝牙socket.获取输入输出流 4,读取和写入数据 5.断开连接关闭蓝牙 还要发送配对码发送进行推断! 以下是全部的源码:不 ...

  8. python入门课程 第二章 安装Python

    2-1 选择python版本首先python2.7和python3是不可以通用的目前丰富的类库都支持python2.7,所以选用Python2.7    选择python2.7版本2-2 window ...

  9. ajax 和jsonp 不是一码事 细读详解

    由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socket通讯 ...

  10. 替换jar包内指定的文件

    用Java jar 工具来替换. ① jar uvf test.jar test.class 把test.class 直接添加到jar包的根目录,也就是替换到根目录文件. ②jar uvf test. ...