Linux小蜗牛

  • head 从文件内容的头部开始查看(默认查看10行)
    [root@oldboyboy tmp]# seq 15 >l.sh
    [root@oldboyboy tmp]# cat l.sh 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [root@oldboyboy tmp]# head l.sh 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@oldboyboy tmp]#
  • head -3 l.sh 查看文件前三行的内容
    [root@oldboyboy tmp]# head -3 l.sh
    1
    2
    3
    [root@oldboyboy tmp]#
  • head -3 l.sh o.txt 同时查看多个文件的前三行

参数ide

  • -c 显示某个文件内容的前几个字符
    head -c 3 o.txt 查看文件中的前3个字符
    [root@oldboyboy tmp]# cat o.txt
    hello   !   my  qq  123.

I am oldboy my qq 1234567
[root@oldboyboy tmp]# head -c 3 o.txt
hel
[root@oldboyboy tmp]# 日志

* tail 从文件内容的末尾开始查看
tail -5 l.sh    查看文件末尾的最后5行

[root@oldboyboy tmp]# tail -5 l.sh
11
12
13
14
15
[root@oldboyboy tmp]# code

参数
-f    用来实时查看文件末尾的内容
tail -f l.sh   实时查看文件末尾的内容,经常使用来查看WEB的日志文件

[root@oldboyboy tmp]# tail -f l.sh
6
7
8
9
10
11
12
13
14
15it

当文件的末尾有新的内容追加时,就会实时显示在文件末尾。
相关文章
相关标签/搜索