linux常用命令-查看文本/cat,tac,more,less,head,tail

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux常用命令-查看文本/cat,tac,more,less,head,tail相关的知识,希望对你有一定的参考价值。

cat:连接并显示文件

NAME
       cat - concatenate files and print on the standard output


[[email protected] ~]# cat /etc/issue
Red Hat Enterprise  Server release 6.6 (Santiago)
\m


[[email protected] ~]# cat /etc/fstab


#
# /etc/fstab
# Created by anaconda on Sun Jun 21 02:15:00 2015
#
# 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
#
UUID=57d85756-7680-4c7c-9125-6ad67dae2c45 /                       ext4    defaults        1 1
UUID=2622a4b4-ddc9-47a3-aa2b-f06bc9bec085 /boot                   ext4    defaults        1 2
UUID=33d94759-fa01-4c4f-b4ac-bf3a1fe5e84f swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
[[email protected] ~]# cat /etc/issue /etc/fstab
Red Hat Enterprise  Server release 6.6 (Santiago)
\m



#
# /etc/fstab
# Created by anaconda on Sun Jun 21 02:15:00 2015
#
# 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
#
UUID=57d85756-7680-4c7c-9125-6ad67dae2c45 /                       ext4    defaults        1 1
UUID=2622a4b4-ddc9-47a3-aa2b-f06bc9bec085 /boot                   ext4    defaults        1 2
UUID=33d94759-fa01-4c4f-b4ac-bf3a1fe5e84f swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
[[email protected] ~]#



-n, --number(显示行号)
              number all output lines

[[email protected] ~]# cat -n /etc/issue
     1 Red Hat Enterprise  Server release 6.6 (Santiago)
     2 \m
     3 


-E, --show-ends(显示结束符号$,windows结束符为$+回车)
              display $ at end of each line

[[email protected] ~]# cat -E /etc/issue
Red Hat Enterprise  Server release 6.6 (Santiago)$
\m$
$


tac:倒叙显示文本

NAME
       tac - concatenate and print files in reverse


[[email protected] ~]# cat /etc/issue
Red Hat Enterprise  Server release 6.6 (Santiago)
\m


[[email protected] ~]# tac /etc/issue


\m
Red Hat Enterprise  Server release 6.6 (Santiago)



more、less:分屏查看

more支持向后翻屏,翻到文章尾部后退出

less不会退出


head:输出文件首部

NAME
       head - output the first part of files

[[email protected] ~]# head /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#


tail:输出文件尾部

NAME
       tail - output the last part of files

[[email protected] ~]# tail /etc/inittab
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
[[email protected] ~]#


-f, --follow[={name|descriptor}] (查看文件尾部后续追加内容)

              output appended data as the file  grows;  -f,  --follow,  and  --follow=descriptor  are
              equivalent


以上是关于linux常用命令-查看文本/cat,tac,more,less,head,tail的主要内容,如果未能解决你的问题,请参考以下文章

1.linux命令之cat和tac

Linux常用命令简述--cat与tac

查看日志文件常用命令:tail,cat,tac,head,echo

Linux命令 查看文件 cat tac more less tail

Linux文本操作常用命令

linux基础命令-文件查看类命令cat/tac/more/less/tail/head