1. more命令简介
本文主要介绍more命令,其作用类似 cat 。cat命令是一次性显示一个文件的所有内容,对于内容较多的文件,显然cat并不合适。 而more会以逐页的方式显示文件内容,使用过程中可按空白键(space)翻往下一页显示,按 b 键翻往(back)前一页,而且还有搜寻字串的功能 。more命令在启动时就加载整个文件,这也是与less命令的区别之一。
2. more命令选项
+n 从笫n行开始显示
-n 定义屏幕大小为n行
+/pattern 在每个档案显示前搜寻该字串(pattern),然后从该字串前两行之后开始显示
-c 从顶部清屏,然后显示
-d 提示“Press space to continue,’q’ to quit(按空格键继续,按q键退出)”,禁用响铃功能
-l 忽略Ctrl+l(换页)字符
-p 通过清除窗口而不是滚屏来对文件进行换页,与-c选项相似
-s 把连续的多个空行显示为一行
-u 把文件内容中的下画线去掉
3. 常用快捷方式
Enter 向下n行,需要定义。默认为1行
Ctrl+F 向下滚动一屏
空格键 向下滚动一屏
Ctrl+B 返回上一屏
= 输出当前行的行号
:f 输出文件名和当前行的行号
V 调用vi编辑器
!命令 调用Shell,并执行命令
q 退出more
4. 常用使用方法
4.1 指定行开始显示
从第4行开始打印某文件的内容,
[root@zcwyou zcwyou]# more +4 /etc/ssh/sshd_config
#sshd_config(5) for more information.
#This sshd was compiled with PATH=/usr/local/bin:/usr/bin
#The strategy used for options in the default sshd_config shipped with
#OpenSSH is to specify options with their default value where
#possible, but leave them commented. Uncommented options override the
#default value.
4.2 从特定关键字开始打印
从文件中查找第一个出现”authentication”字符串的行,并从该处前两行开始显示输出
[root@zcwyou zcwyou]# more +/authentication /etc/ssh/sshd_config
跳过
#GSSAPIEnablek5users no
#Set this to ‘yes’ to enable PAM authentication, account processing,
#and session processing. If this is enabled, PAM authentication will
#be allowed through the ChallengeResponseAuthentication and
#PasswordAuthentication. Depending on your PAM configuration,
#PAM authentication via ChallengeResponseAuthentication may bypass
#the setting of “PermitRootLogin without-password”.
#If you just want the PAM account and session checks to run without
4.3 设定每屏显示行数
查看more手册,并设定每次只显示5行。
[root@zcwyou zcwyou]# man more |more -5
Ctrl+F 向下滚动一屏
空格键 向下滚动一屏
Ctrl+B 返回上一屏
4.4 使用more优化打印输出
查看进程时结合more打印内容
[root@zcwyou zcwyou]# ps -ef |more
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 11月27 ? 00:00:30 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0 0 11月27 ? 00:00:00 [kthreadd]
root 3 2 0 11月27 ? 00:00:00 [rcu_gp]
root 4 2 0 11月27 ? 00:00:00 [rcu_par_gp]
root 6 2 0 11月27 ? 00:00:00 [kworker/0:0H-kb]
root 8 2 0 11月27 ? 00:00:00 [mm_percpu_wq]
root 9 2 0 11月27 ? 00:00:01 [ksoftirqd/0]
root 10 2 0 11月27 ? 00:00:28 [rcu_sched]
root 11 2 0 11月27 ? 00:00:00 [rcu_bh]
root 12 2 0 11月27 ? 00:00:00 [migration/0]
root 13 2 0 11月27 ? 00:00:00 [watchdog/0]
root 14 2 0 11月27 ? 00:00:00 [cpuhp/0]
总结:more命令可以结合其他工具优化信息或者日志的输出,方便运维人员阅读输出信息。
评论前必须登录!
注册