Linux文本查看命令

一、cat 命令

用途: 用于查看文本内容

适用场景:由于不能分页输出,所以只适用于查看 小文本文件内容。

常用法:

[root@www ~]# cat /etc/issue            # 输出/etc/issue文件内容 
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel \r on an \m

[root@www ~]# cat -n /etc/issue         # -n 选项表示带行号输出文件内容
     1	Red Hat Enterprise Linux Server release 6.5 (Santiago)
     2	Kernel \r on an \m
     3	
[root@www ~]# 

二、tac 命令

用途:用于倒叙方式查看文本内容, 与cat命令查看内容相反。

适用场景:也适用于查看小文本文件内容。

常用法:

[root@www ~]# cat /etc/issue                # 正序输出文本内容
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel \r on an \m

[root@www ~]# tac /etc/issue                # 倒叙输出文本内容

Kernel \r on an \m
Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@www ~]# 

三、head 命令

用途:用于查看文件头几行内容。

适用场景:适用于查看大文本文件头几行内容,不需要查看文本的所有内容。

常用法:

[root@www ~]# head -n 10 /etc/passwd            # -n 10 表示查看文件的前 10 行内容
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
[root@www ~]# 
[root@www ~]# 
[root@www ~]# head  /etc/passwd                 # 相当于 head -n 10 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
[root@www ~]# 

四、tail 命令

用途:查看文件最后几行的内容。

适用场景:一般用于查看文件的最后面几行的内容,与 head 命令相反

[root@www ~]# tail -5 /etc/passwd            # 查看文件最后5行的内容
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
[root@www ~]# 

五、more 命令

用途:具有翻页功能, 用来查看大文件内容。

适用场景:只能向后翻页,不能向前翻页,一般查看大文件内容都是用 less 命令。

常用法:

[root@www ~]# more /etc/passwd                   # 1.按 enter回车键向下翻一行
root:x:0:0:root:/root:/bin/bash                  # 2.按 空格键 向下翻一页
bin:x:1:1:bin:/bin:/sbin/nologin                 # 3.按 /关键字 向下查找关键字
daemon:x:2:2:daemon:/sbin:/sbin/nologin          # 4.按 q 退出
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
[root@www ~]# 

六、less 命令

用途:用于查看大文件的内容。

适用场景:具有向前、向后的翻页,向前、向后检索文件内容的功能

常用法:

[root@www ~]# less /etc/man.config         # 1.按键盘的上下键,可以上下翻一行
                                           # 2.按enter回车键, 可以向下翻一行
                                           # 3.按 /关键字, 向下查找关键字
                                           # 4.按 ?关键字, 向上查找关键字
                                           # 5.按 n ,表示查找下一个关键字
                                           # 6.按 N, 反向查找下一个关键字
                                           # 7.按 q 退出

#
# Generated automatically from man.conf.in by the
# configure script.
#
# man.conf from man-1.6f
#
# For more information about this file, see the man pages man(1)
# and man.conf(5).
#
# This file is read by man to configure the default manpath (also used
# when MANPATH contains an empty substring), to find out where the cat
# pages corresponding to given man pages should be stored,
# and to map each PATH element to a manpath element.
# It may also record the pathname of the man binary. [This is unused.]
# The format is:
#
# MANBIN                pathname
# MANPATH               manpath_element [corresponding_catdir]
# MANPATH_MAP           path_element    manpath_element
#
# If no catdir is given, it is assumed to be equal to the mandir
# (so that this dir has both man1 etc. and cat1 etc. subdirs).
# This is the traditional Unix setup.
# Certain versions of the FSSTND recommend putting formatted versions
# of /usr/.../man/manx/page.x into /var/catman/.../catx/page.x.
# The keyword FSSTND will cause this behaviour.
# Certain versions of the FHS recommend putting formatted versions of
# /usr/.../share/man/[locale/]manx/page.x into
# /var/cache/man/.../[locale/]catx/page.x.
# The keyword FHS will cause this behaviour (and overrides FSSTND).
# Explicitly given catdirs override.
#
# FSSTND
FHS

猜你喜欢

转载自blog.csdn.net/u010559460/article/details/87929856