每天一个linux命令(12):more命令
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上。 more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(back)一页显示,而且还有搜寻字串的功能 。more命令从前向后读取文件,因此在启动时就加载整个文件。
1.命令格式:
more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ]
2.命令功能:
more命令和cat的功能一样都是查看文件里的内容,但有所不同的是more可以按页来查看文件的内容,还支持直接跳转行等功能。
3.命令参数:
- +n 从笫n行开始显示
- -n 定义屏幕大小为n行
- +/pattern 在每个档案显示前搜寻该字串(pattern),然后从该字串前两行之后开始显示
- -c 从顶部清屏,然后显示
- -d 提示“Press space to continue,’q’ to quit(按空格键继续,按q键退出)”,禁用响铃功能
- -l 忽略Ctrl+l(换页)字符
- -p 通过清除窗口而不是滚屏来对文件进行换页,与-c选项相似
- -s 把连续的多个空行显示为一行
- -u 把文件内容中的下画线去掉
4.常用操作命令:
- Enter 向下n行,需要定义。默认为1行
- Ctrl+F 向下滚动一屏
- 空格键 向下滚动一屏
- Ctrl+B 返回上一屏
- = 输出当前行的行号
- :f 输出文件名和当前行的行号
- V 调用vi编辑器
- !命令 调用Shell,并执行命令
- q 退出more
5.命令实例:
实例1:显示文件中从第3行起的内容
命令:more +3 demo3.log
输出:
[root@localhost test]# cat demo3.log
hello
world
demo_1是也
hello
world
demo_2是也
[root@localhost test]# more +3 demo3.log
demo_1是也
hello
world
demo_2是也
[root@localhost test]#
实例2:从文件中查找第一个出现"demo_1 "字符串的行,并从该处前两行开始显示输出
命令: more +/demo_1 demo3.log
输出:
[root@localhost test]# more +/demo_1 demo3.log
…skipping
world
demo_1是也
hello
world
demo_2是也
[root@localhost test]#
实例3:设定每屏显示行数
命令:more -5 log2012.log
输出:
[root@localhost test]# more -5 log2012.log
2012-01
2012-02
2012-03
2012-04-day1
2012-04-day2
说明:
- 如下图所示,最下面显示了该屏展示的内容占文件总行数的比例,按 Ctrl+F 或者 空格键 将会显示下一屏5条内容,百分比也会跟着变化。
实例4:列一个目录下的文件,由于内容太多,我们应该学会用more来分页显示。这得和管道 | 结合起来
命令:ls -l | more -5
输出:
[root@localhost test]# ls -l | more -5
total 572
-rwxrwxrwx 1 UNIX UNIX 568296 Jan 30 15:35 2018.wav
drwxrwxrwx 1 UNIX UNIX 4096 May 25 11:31 d
-rwxrwxrwx 1 UNIX UNIX 7893 May 25 11:29 de
drwxrwxrwx 1 UNIX UNIX 4096 May 18 12:12 demo1
…skipping 1 line
-rwxrwxrwx 1 UNIX UNIX 25 May 25 12:14 demo2.log
-rwxrwxrwx 1 UNIX UNIX 51 Jun 1 11:28 demo3.log
-rwxrwxrwx 1 UNIX UNIX 72 May 25 12:30 demo3.txt
-rwxrwxrwx 1 UNIX UNIX 0 May 25 12:11 demo.log
drwxrwxrwx 1 UNIX UNIX 4096 May 18 11:19 dvsdf
…skipping 1 line
-rwxrwxrwx 1 UNIX UNIX 12 May 25 12:02 log2012.log
-rwxrwxrwx 1 UNIX UNIX 6 May 25 12:02 log2013.log
-rwxrwxrwx 1 UNIX UNIX 3 May 25 12:02 log.log
-rwxrwxrwx 1 UNIX UNIX 0 May 25 12:12 log.txt
lrwxrwxrwx 1 UNIX UNIX 10 May 25 11:35 ne_link.html -> new 5.html
…skipping 1 line
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNCOMMERCIALBUG-409
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-1683_保存按钮
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-3132_住院号整改
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-3332_牟定异地医保_行转列
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-3350_权责发生
…skipping 1 line
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-3360_科室收入分类
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-3365_重庆铭博
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-3632_表头
drwxrwxrwx 1 UNIX UNIX 4096 Oct 21 2018 YUNHIS-3644_门诊科室统计方式
说明:
- 每页显示5个文件信息,按 Ctrl+F 或者 空格键 将会显示下5条文件信息。