liunx中组合查询的命令

                            今天无聊,把以前的 liunx 命令拿过练练,尤其是一些组合命令并带有逻辑的。这里的 script 是一个文件夹。

1. 查看一个文件的最后 3 行的第一行。

  [root@localhost home]# tail -n -3 script | head -n +1

2. 查看一个文件的最后的 13 行前 7 行

[root@localhost home]# tail -n 13 script | head -n 7

3. 查看 script 文件的前两行

[root@localhost home]# head -n 2 script

4. 显示除最后 3 行以外的所有行,但只显示最后 10 行

[root@localhost home]# head -n -3 script | tail -n 10

5. 显示最后 13 行中的前 10 行

[root@localhost home]# tail -n 13 jingdong |head -n -3

[root@localhost home]# tail -n 13 jingdong |head -n 10

6. 最后五行内容

tail -n -5 jingdong 

7. 从正数第五行到结尾的所有内容 少前 4 行

tail –n +5 jingdong

head 与 tail 区别

head 输出文件的头部  默认显示前 10 行的内容

tail 输出文件的尾部  tail -f 查看动态的 film.log

跟 tail 功能相似的命令:

  • cat 从第一行開始显示档案内容
  • tac 从最后一行開始显示档案内容
  • more 分页显示档案内容
  • less 与 more 相似,但支持向前翻页
  • head 仅仅显示前面几行 (n 带行号显示档案内容)
  • tail 仅仅显示后面几行 (n 带行号显示档案内容)
  • od 以二进制方式显示档案内容