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

當文件的末尾有新的內容追加時,就會實時顯示在文件末尾。
相關文章
相關標籤/搜索