linux常用命令

文件查看及处理命令-02-more命令

2020-11-23  本文已影响0人  夏胖运维

1. 命令介绍

more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上。 more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(back)一页显示,而且还有搜寻字串的功能 。more命令从前向后读取文件,因此在启动时就加载整个文件。

2. 命令格式

more [options] file...

3. 命令功能

more命令和cat的功能一样都是查看文件里的内容,但有所不同的是more可以按页来查看文件的内容,还支持直接跳转行等功能。

4. 常用选项

选项 含义
+n 从笫n行开始显示
-n 定义屏幕大小为n行
+/pattern 在每个档案显示前搜寻该字串(pattern),然后从该字串前两行之后开始显示
-c 从顶部清屏,然后显示
-d 提示“Press space to continue,’q’ to quit(按空格键继续,按q键退出)”,禁用响铃功能
-l 忽略Ctrl+l(换页)字符
-p 通过清除窗口而不是滚屏来对文件进行换页,与-c选项相似
-s 把连续的多个空行显示为一行
-u 把文件内容中的下画线去掉

5.常用命令操作

选项 含义
Enter 向下n行,需要定义。默认为1行
Ctrl+F 向下滚动一屏
空格键 向下滚动一屏
Ctrl+B 返回上一屏
= 输出当前行的行号
:f 输出文件名和当前行的行号
V 调用vi编辑器
!命令 调用Shell,并执行命令
q 退出more

6. 常用实例

  1. 显示文件中从第3行起的内容
[root@localhost ~]# cat -n /etc/rc.local 
     1  #!/bin/bash
     2  # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
     3  #
     4  # It is highly advisable to create own systemd services or udev rules
     5  # to run scripts during boot instead of using this file.
     6  #
     7  # In contrast to previous versions due to parallel execution during boot
     8  # this script will NOT be run after all other services.
     9  #
    10  # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
    11  # that this script will be executed during boot.
    12  
    13  touch /var/lock/subsys/local
[root@localhost ~]# more +3 /etc/rc.local
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
  1. 从文件中查找第一个出现"chmod"字符串的行,并从该处前两行开始显示输出
[root@localhost ~]# more +/chmod /etc/rc.local 

...skipping
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
  1. 设定每屏显示行数
[root@localhost ~]# more -5 /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
--More--(39%)

如下图所示,最下面显示了该屏展示的内容占文件总行数的比例,按 Ctrl+F 或者 空格键 将会显示下一屏5条内容,百分比也会跟着变化。

  1. 列一个目录下的文件,由于内容太多,我们应该学会用more来分页显示。这得和管道 | 结合起来
[root@localhost log]# ls -l|more -5
total 1884
drwxr-xr-x. 2 root root    204 May 24  2020 anaconda
drwx------. 2 root root     23 May 24  2020 audit
-rw-------. 1 root root   8486 Nov 24 02:00 boot.log
-rw-------. 1 root root  44498 Nov 22 03:32 boot.log-20201122

...skipping one line
-rw-------. 1 root utmp    384 May 24  2020 btmp
-rw-------. 1 root root   9176 Nov 24 02:01 cron
-rw-------. 1 root root   6086 Nov 22 03:32 cron-20201122
-rw-r--r--. 1 root root 122877 Nov 24 02:00 dmesg
-rw-r--r--. 1 root root 123064 Nov 23 03:54 dmesg.old

...skipping one line
-rw-r--r--. 1 root root    193 May 24  2020 grubby_prune_debug
-rw-r--r--. 1 root root 292000 Nov 24 02:01 lastlog
-rw-------. 1 root root    594 Nov 24 02:00 maillog
-rw-------. 1 root root    990 Nov 21 14:15 maillog-20201122
-rw-------. 1 root root 666402 Nov 24 02:15 messages

...skipping one line
drwxr-xr-x. 2 root root      6 May 24  2020 rhsm
-rw-------. 1 root root   2418 Nov 24 02:01 secure
-rw-------. 1 root root   2218 Nov 21 14:16 secure-20201122
-rw-------. 1 root root      0 Nov 22 03:32 spooler
-rw-------. 1 root root      0 May 24  2020 spooler-20201122

...skipping one line
drwxr-xr-x. 2 root root     23 May 24  2020 tuned
-rw-r--r--. 1 root root  12257 Nov 24 02:00 vmware-vgauthsvc.log.0
-rw-r--r--. 1 root root  17025 Nov 24 02:00 vmware-vmsvc.log
-rw-rw-r--. 1 root utmp  19200 Nov 24 02:01 wtmp

说明:每页显示5个文件信息,按 Ctrl+F 或者 空格键 将会显示下5条文件信息。

上一篇 下一篇

猜你喜欢

热点阅读