美文网首页
linux文件查看类命令总结及演示

linux文件查看类命令总结及演示

作者: 香吉矢 | 来源:发表于2017-08-23 21:58 被阅读0次

    head,tail,cat,more,less

    head
    • image.png
    • 命令演示
      [root@localhost mytest]# head -n 12 passwd.test
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      root:x:0:0:root:/root:/bin/bash
      [root@localhost mytest]# head -12 passwd.test
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      root:x:0:0:root:/root:/bin/bash

    tail
    • image.png
    • 命令演示
      [root@localhost mytest]# tail -n 3 passwd.test
      ntp:x:38:38::/etc/ntp:/sbin/nologin
      avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
      tcpdump:x:72:72::/:/sbin/nologin
      [root@localhost mytest]#
      [root@localhost mytest]# tail -3 passwd.test
      ntp:x:38:38::/etc/ntp:/sbin/nologin
      avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
      tcpdump:x:72:72::/:/sbin/nologin

      • 另开一ssh窗口,对passwd文件进行修改
        [root@localhost mytest]# tty
        /dev/pts/4
        [root@localhost mytest]# echo 'linux centos fedora suse RHEL' >> passwd
        [root@localhost mytest]# echo 'linux centos fedora suse RHEL' >> passwd
        [root@localhost mytest]# echo 'linux centos fedora suse RHEL' >> passwd
        [root@localhost mytest]# echo 'linux centos fedora suse RHEL' >> passwd
        [root@localhost mytest]# echo 'linux centos fedora suse RHEL' >> passwd
      • 在第一个ssh窗口,执行查看命令 tail -f passwd,不会自动退出文件,可以看到文件内容在增加
        [root@localhost mytest]# tail -f passwd
        3
        4
        5
        6
        7
        8
        9
        10
        11
        linux centos fedora suse RHEL
        linux centos fedora suse RHEL
        linux centos fedora suse RHEL
        linux centos fedora suse RHEL
        linux centos fedora suse RHEL
    cat
    • image.png
    • 命令演示
      [root@localhost mytest]# cat redhat-release
       
       
       
      CentOS Linux release 7.3.1611 (Core)
       
       
      [root@localhost mytest]# cat version
      Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
      [root@localhost mytest]# cat redhat-release version
       
       
       
      CentOS Linux release 7.3.1611 (Core)
       
       
      Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
      [root@localhost mytest]# cat > newfile
      my name is zhanmusi
      see you next week
      ^C
      [root@localhost mytest]#
      [root@localhost mytest]# cat newfile
      my name is zhanmusi
      see you next week
      [root@localhost mytest]# cat hebing
      cat: hebing: 没有那个文件或目录
      [root@localhost mytest]# cat redhat-release redhat-release newfile > hebing
      [root@localhost mytest]# cat hebing
       
       
       
      CentOS Linux release 7.3.1611 (Core)
       
       
       
       
       
      CentOS Linux release 7.3.1611 (Core)
       
       
      my name is zhanmusi
      see you next week
      [root@localhost mytest]# cat -n hebing
      1
      2
      3
      4 CentOS Linux release 7.3.1611 (Core)
      5
      6
      7
      8
      9
      10 CentOS Linux release 7.3.1611 (Core)
      11
      12
      13 my name is zhanmusi
      14 see you next week
      [root@localhost mytest]# cat -b hebing
       
       
       
      1 CentOS Linux release 7.3.1611 (Core)
       
       
       
       
       
      2 CentOS Linux release 7.3.1611 (Core)
       
       
      3 my name is zhanmusi
      4 see you next week
      [root@localhost mytest]# cat -E hebing
      $
      $
      $
      CentOS Linux release 7.3.1611 (Core)$
      $
      $
      $
      $
      $
      CentOS Linux release 7.3.1611 (Core)$
      $
      $
      my name is zhanmusi$
      see you next week$
      [root@localhost mytest]#

    more
    • image.png
    • 命令演示
      [root@localhost mytest]# more -15 fstab.test
      1
      2
      3
      4
      5
       
       
       
       
       
      # /etc/fstab
      # Created by anaconda on Tue May 30 06:31:44 2017

    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    --More--(32%)
    [root@localhost mytest]# more +5 fstab.test
    5

    # /etc/fstab
    # Created by anaconda on Tue May 30 06:31:44 2017

    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    /dev/mapper/cl-root / xfs defaults 0 0
    UUID=8be7dbe5-dde6-40b0-8900-c30f1007287e /boot xfs defaul
    ts 0 0
    /dev/mapper/cl-swap swap swap defaults 0 0
    [root@localhost mytest]# more -s fstab.test
    1
    2
    3
    4
    5

    # /etc/fstab
    # Created by anaconda on Tue May 30 06:31:44 2017

    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

    /dev/mapper/cl-root / xfs defaults 0 0
    UUID=8be7dbe5-dde6-40b0-8900-c30f1007287e /boot xfs defaul
    ts 0 0
    /dev/mapper/cl-swap swap swap defaults 0 0
    [root@localhost mytest]# more +/2017 fstab.test
     
    ...跳过

    # /etc/fstab
    # Created by anaconda on Tue May 30 06:31:44 2017
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

    /dev/mapper/cl-root / xfs defaults 0 0
    UUID=8be7dbe5-dde6-40b0-8900-c30f1007287e /boot xfs defaul
    ts 0 0
    /dev/mapper/cl-swap swap swap defaults 0 0
    [root@localhost mytest]# more +/4 fstab.test
     
    ...跳过
    2
    3
    4
    5

    # /etc/fstab
    # Created by anaconda on Tue May 30 06:31:44 2017

    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

    /dev/mapper/cl-root / xfs defaults 0 0
    UUID=8be7dbe5-dde6-40b0-8900-c30f1007287e /boot xfs defaul
    ts 0 0
    /dev/mapper/cl-swap swap swap defaults 0 0
    [root@localhost mytest]# cat -n fstab.test | more
    1 1
    2 2
    3 3
    4 4
    5 5
    6
    7
    8
    9
    10
    11 #
    12 # /etc/fstab
    13 # Created by anaconda on Tue May 30 06:31:44 2017
    14 #
    15 # Accessible filesystems, by reference, are maintained under '/dev/disk'
    16 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    17 #
    18 /dev/mapper/cl-root / xfs defaults 0 0
    19 UUID=8be7dbe5-dde6-40b0-8900-c30f1007287e /boot xfs defaults 0 0
    20 /dev/mapper/cl-swap swap swap defaults 0 0

    less
    • image.png
    • 命令演示
      由于more命令查看大文件后,屏幕占用效果不是很好,就不再展示详细执行过程。

    相关文章

      网友评论

          本文标题:linux文件查看类命令总结及演示

          本文链接:https://www.haomeiwen.com/subject/vywjdxtx.html