linux文件查看類命令總結(jié)及演示

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文件進(jìn)行修改
      [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窗口,執(zhí)行查看命令 tail -f passwd,不會自動退出文件,可以看到文件內(nèi)容在增加
      [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命令查看大文件后,屏幕占用效果不是很好,就不再展示詳細(xì)執(zhí)行過程。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容