当前位置: 首页 > news >正文

Linux 常用命令 - more 【分页显示文件内容】

简介

more 命令源自英文单词 more, 表示 “更多”,它是一个基于文本的程序,用于查看文本文件的内容。该命令会逐页显示文件内容,允许用户按页浏览大型文本文件。当用户完成当前页的阅读后,可以通过按键(空格键或回车键)浏览到下一页。这种方式非常适合查看较长的日志文件或任何大型文本。

使用方式

more [选项] 文件...

常用选项

  • -d:显示提示信息,并且关闭提示音(当按下无效按键)。

  • -l:将 ^L (换页符)作为普通字符处理,而不是暂停输出内容。

  • -f:统计逻辑行(实际的行数),而不是屏幕行(对于很长的行会自动换行显示,从而变成多行屏幕行)。

  • -p:显示新页面时不滚动屏幕,而是清除屏幕内容然后显示新的文本。

  • -c:显示新页面时不滚动屏幕,而是先从顶部开始显示新内容,然后清除剩余的内容。

  • -s:将多个空白行压缩成一行显示。

  • -u:不显示下划线。

  • -number:指定每次屏幕显示的最大行数为 number

  • +number:从指定的行号开始显示内容。

  • +/string:从指定的字符串开始显示文件内容。

  • --help:显示帮助信息。

  • -V--version:显示版本信息。

交互指令

more 命令的交互指令基于 vi 。一些命令可能在前面加一个十进制的数,这个数在下面被称为 k。在接下来的描述中,^X 代表 Ctrl + X

  • h?:显示帮助信息。

  • 空格:显示接下来的 k 行文本,默认为当前屏幕大小的行数。

  • z:显示接下来的 k 行文本,默认情况下显示当前屏幕大小的行数。如果指定了参数则该参数会成为新的默认值。

  • 回车:显示接下来的 k 行文本,默认情况下显示 1 行。如果指定了参数则该参数会成为新的默认值。

  • d^D:向下滚动 k 行。默认情况下滚动当前设置的行数,初始值为 11 行。如果指定了参数则该参数会成为新的默认值。

  • qQINTERRUPT(中断信号):退出 more 命令。

  • s:向前跳过 k 行文本,默认跳过 1 行。

  • f:向前跳过 k 个屏幕的文本,默认跳过一个屏幕。

  • b^B:向后跳过 k 个屏幕的文本。默认跳过 1 个屏幕。这个命令仅在文件中有效,不适用于管道。

  • ':跳转到上次搜索开始的位置。

  • =:显示当前行号。

  • /pattern:搜索正则表达式 pattern 的第 k 次出现。默认情况下搜索第 1 次出现。

  • n:搜索上一个正则表达式的第 k 次出现。默认情况下搜索第 1 次出现。

  • !command:!command:在子命令行中执行命令。

  • v:在当前行启动一个编辑器。编辑器的选择依据环境变量 VISUAL,如果 VISUAL 未定义,则使用 EDITOR,如果 VISUALEDITOR 都未定义,则默认为 vi

  • ^L:重绘屏幕。

  • :n:跳转到后面第 k 个文件。默认跳转到下一个文件。

  • :p:跳转到之前的第 k 个文件。默认跳转到上一个文件。

  • :f:显示当前文件名和行号。

  • .:重复前一个命令。

环境变量

以下环境变量会影响 more 命令:

  • MORE:该环境变量可以设置 more 命令的默认启用选项。

  • SHELL:当前使用的 shell(通常在登录时由 shell 设置)。

  • TERM:用来获取终端类型的环境变量,以便得到必要的终端特性来操作屏幕。

  • VISUAL:指定在按下命令键 v 时调用的编辑器。

  • EDITOR:当 VISUAL 未指定时的选择编辑器。

参考示例

1. 分页显示文件内容

more more.txt 

使用 more 文件名 可以分页显示指定文件的内容:


MORE(1)                                                                                                                                                     User Commands    MORE(1)NAMEmore - file perusal filter for crt viewingSYNOPSISmore [options] file...DESCRIPTIONmore is a filter for paging through text one screenful at a time.  This version is especially primitive.  Users should realize that less(1) provides more(1) emulationplus extensive enhancements.OPTIONSOptions are also taken from the environment variable MORE (make sure to precede them with a dash (-)) but command-line options will override those.-d     Prompt with "[Press space to continue, 'q' to quit.]", and display "[Press 'h' for instructions.]" instead of ringing the bell when an illegal key is pressed.
--More--(17%)

2. 显示提示信息

more -d more.txt

使用 -d 选项可以在尾部显示提示信息,用于指示基础交互命令的操作:

MORE(1)                                                                                                                                                     User Commands    MORE(1)NAMEmore - file perusal filter for crt viewingSYNOPSISmore [options] file...DESCRIPTIONmore is a filter for paging through text one screenful at a time.  This version is especially primitive.  Users should realize that less(1) provides more(1) emulationplus extensive enhancements.OPTIONSOptions are also taken from the environment variable MORE (make sure to precede them with a dash (-)) but command-line options will override those.-d     Prompt with "[Press space to continue, 'q' to quit.]", and display "[Press 'h' for instructions.]" instead of ringing the bell when an illegal key is pressed.
--More--(17%)[Press space to continue, 'q' to quit.]

3. 先清屏,然后以每次10行的内容显示文件内容

more -c -10 more.txt

使用 -c 选项使 more 指令在显示时先进行清屏,然后再使用 -10 指定显示 10 行的内容:

MORE(1)                                                                                                                                                     User Commands    MORE(1)NAMEmore - file perusal filter for crt viewingSYNOPSISmore [options] file...DESCRIPTION
--More--(8%)

4. 从第10行开始显示内容

more +10 more.txt 

使用 +10 选项可以指定从文件的第 10 行开始显示:

       more is a filter for paging through text one screenful at a time.  This version is especially primitive.  Users should realize that less(1) provides more(1) emulationplus extensive enhancements.OPTIONSOptions are also taken from the environment variable MORE (make sure to precede them with a dash (-)) but command-line options will override those.-d     Prompt with "[Press space to continue, 'q' to quit.]", and display "[Press 'h' for instructions.]" instead of ringing the bell when an illegal key is pressed.-l     Do not pause after any line containing a ^L (form feed).-f     Count logical lines, rather than screen lines (i.e., long lines are not folded).-p     Do not scroll.  Instead, clear the whole screen and then display the text.  Notice that this option is switched on automatically if the executable is named pag
e.-c     Do not scroll.  Instead, paint each screen from the top, clearing the remainder of each line as it is displayed.--More--(26%)

5. 从指定字符串开始显示内容

more +/COMMANDS more.txt

使用 +/字符串 可以从指定字符串开始显示内容:

              Display version information and exit.COMMANDSInteractive commands for more are based on vi(1).  Some commands may be preceded by a decimal number, called k in the descriptions below.  In the following descriptio
ns, ^X means control-X.h or ?    Help; display a summary of these commands.  If you forget all other commands, remember this one.SPACE     Display next k lines of text.  Defaults to current screen size.z         Display next k lines of text.  Defaults to current screen size.  Argument becomes new default.RETURN    Display next k lines of text.  Defaults to 1.  Argument becomes new default.d or ^D   Scroll k lines.  Default is current scroll size, initially 11.  Argument becomes new default.q or Q or INTERRUPT
--More--(49%)

注意事项

  • more 命令在处理大文件时效率较低,相比之下 less 命令功能更丰富且效率更高。

  • 使用 more 命令时,需要注意文件路径和权限,确保文件存在且具有读取权限。

  • more 命令默认只支持从前向后浏览文件内容,没有很好地支持向上滚动。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • react + antDesign封装图片预览组件(支持多张图片)
  • 全面掌握大模型:从零基础到精通的终极指南,超详细教程手把手教会你,收藏我这一篇就够了
  • Java笔试面试题AI答之设计模式(5)
  • python gensim实现作者主题模型(Author-Topic Model)
  • 车路云一体化大模型数据治理方案
  • 什么是RTOS操作系统
  • 内核驱动开发之系统移植
  • mysql update语句的执行流程
  • PDB数据库中蛋白质结构文件数据格式
  • Python 类class的用法详解
  • 《重生之我在java世界做任务升级》--第一章
  • 免费的跨平台剪贴板工具,超好用!
  • 【计算机网络】计算机网络基础二
  • Java Web服务运行一段时间后出现cpu升高导致的性能下降问题排查
  • C++ std::find函数 容器元素查找
  • [译]前端离线指南(上)
  • CSS 三角实现
  • css布局,左右固定中间自适应实现
  • php中curl和soap方式请求服务超时问题
  • Python利用正则抓取网页内容保存到本地
  • Quartz实现数据同步 | 从0开始构建SpringCloud微服务(3)
  • Redis的resp协议
  • Spring-boot 启动时碰到的错误
  • SpringBoot几种定时任务的实现方式
  • VuePress 静态网站生成
  • Webpack入门之遇到的那些坑,系列示例Demo
  • web标准化(下)
  • 百度小程序遇到的问题
  • 给Prometheus造假数据的方法
  • 开源SQL-on-Hadoop系统一览
  • 来,膜拜下android roadmap,强大的执行力
  • 强力优化Rancher k8s中国区的使用体验
  • 说说动画卡顿的解决方案
  • 微信小程序填坑清单
  • 问题之ssh中Host key verification failed的解决
  • 栈实现走出迷宫(C++)
  • scrapy中间件源码分析及常用中间件大全
  • shell使用lftp连接ftp和sftp,并可以指定私钥
  • ​​​​​​​sokit v1.3抓手机应用socket数据包: Socket是传输控制层协议,WebSocket是应用层协议。
  • #Datawhale AI夏令营第4期#AIGC方向 文生图 Task2
  • $.ajax()参数及用法
  • (1综述)从零开始的嵌入式图像图像处理(PI+QT+OpenCV)实战演练
  • (3)STL算法之搜索
  • (C语言)球球大作战
  • (Qt) 默认QtWidget应用包含什么?
  • (windows2012共享文件夹和防火墙设置
  • (安卓)跳转应用市场APP详情页的方式
  • (博弈 sg入门)kiki's game -- hdu -- 2147
  • (二)测试工具
  • (二刷)代码随想录第15天|层序遍历 226.翻转二叉树 101.对称二叉树2
  • (附源码)小程序儿童艺术培训机构教育管理小程序 毕业设计 201740
  • (十三)MipMap
  • (转)Oracle存储过程编写经验和优化措施
  • (自用)learnOpenGL学习总结-高级OpenGL-抗锯齿
  • .【机器学习】隐马尔可夫模型(Hidden Markov Model,HMM)