Linux小蜗牛

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 同时查看多个文件的前三行

参数

  • -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]#


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

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


当文件的末尾有新的内容追加时,就会实时显示在文件末尾。

以上是关于Linux小蜗牛的主要内容,如果未能解决你的问题,请参考以下文章

Linux小蜗牛

Linux小蜗牛

nyoj-647-奋斗小蜗牛在请客(进制转换)

#WordPress小技巧#纯代码为自己博客添加支付宝/微信打赏功能

小蜗牛快递

linux中怎么查看mysql数据库版本