Linux 管理员 - more 和 less 命令



moreless 命令都可以对大型文本文件进行分页。浏览大型文件时,若不知道要搜索的确切字符串,不一定能够使用 grep。因此,我们希望使用 more 或 less。

通常,less 是首选,因为它允许对分页文本进行向前和向后浏览。但是,在较旧的 Linux 发行版,甚至在一些现代 Unix 操作系统上,默认安装时可能没有 less。

[root@centosLocal Documents]# grep "192.168" ./pfirewall.log | more 
2016-01-07 15:36:34 DROP UDP 192.168.0.1 255.255.255.255 68 67 328 - - - - -  -  RECEIVE 
2016-01-07 15:36:38 DROP UDP 192.168.0.21 255.255.255.255 68 67 328 - - - - -- - RECEIVE 
2016-01-07 15:36:45 DROP ICMP 192.168.0.24 224.0.0.1 - - -- - - - - -- - - - -   RECEIVE 
2016-01-07 15:37:07 DROP UDP 192.168.0.21 255.255.255.255 68 67 328 - - - -  - - RECEIVE 
2016-01-07 15:37:52 DROP UDP 192.168.0.78 255.255.255.255 68 67 328 - - - -  - - RECEIVE 
2016-01-07 15:37:52 ALLOW UDP 192.168.0.78 255.255.255.255 67 68 0 - - - - -- -  RECEIVE 
2016-01-07 15:37:53 ALLOW UDP 192.168.0.78 224.0.0.252 51571 5355 0 - - - -  - - RECEIVE

less 通常更受欢迎,这是因为它确实提供了比 more 更多功能。

2016-01-07 15:43:53 DROP UDP 192.168.1.73 255.255.255.255 68 67 328 - - - - - -  RECEIVE 
2016-01-07 15:44:17 ALLOW UDP 192.168.1.18 224.0.0.252 54526 5355 0 - - - - - -  RECEIVE 
2016-01-07 15:44:23 DROP UDP 192.168.1.57 255.255.255.255 68 67 328 - - - - - -  RECEIVE 
2016-01-07 15:44:33 DROP UDP 192.168.1.88 255.255.255.255 68 67 328 - - - - - -  RECEIVE 
2016-01-07 15:44:33 ALLOW UDP 192.168.1.4 255.255.255.255 67 68 0 - - - - - - -  RECEIVE 
2016-01-07 15:44:41 DROP UDP 192.168.1.126 255.255.255.255 68 67 328 - - - - - - RECEIVE 
2016-01-07 15:44:43 DROP UDP 192.168.1.112 255.255.255.255 68 67 328 - - - - - - RECEIVE 
2016-01-07 15:44:56 DROP ICMP 192.168.1.240 224.0.0.1 - - 36 - - - - 9 0 -       RECEIVE 
2016-01-07 15:45:57 ALLOW UDP 192.168.1.47 192.168.1.255 138 138 0 - - - - - -      SEND 
2016-01-07 15:49:13 DROP ICMP 192.168.1.241 224.0.0.1 - - 36 - - - - 9 0 -       RECEIVE 
2016-01-07 15:49:38 DROP UDP 192.168.1.68 255.255.255.255 68 67 328 - - - - - -  RECEIVE 
2016-01-07 15:49:38 ALLOW UDP 192.168.1.4 255.255.255.255 67 68 0 - - - - - -    RECEIVE 
2016-01-07 15:49:39 DROP UDP 192.168.1.93 255.255.255.255 68 67 328 - - - - -    RECEIVE 
:

如上所示,调用 less 时,它会在与 shell 提示分开的缓冲区中打开。尝试 less 时,有时候可能会出现如下错误:

bash: less: command not found...

从包管理器的源中使用 more 或安装 less。但是,less 应包含在所有现代 Linux 发行版中,甚至移植到 Unix 平台中。有些甚至会 more 链接 到 less

basic_centos_linux_commands.htm
广告