1、cat
NAME
cat - concatenate files and print on the standard output
连接所有指定文件并将结果写到标准输出。【经常用来显示文件的内容,类似DOS的TYPE 命令】
SYNOPSIS
cat [OPTION]... [FILE]...
cat [选项]... [文件]...
With no FILE, or when FILE is -, read standard input.
如果没有指定文件,或者文件为"-",则从标准输入读取。
cat命令有两项功能:
一是显示文件的内容,以此读取由参数file指明的文件,将他们的内容输出到标准输出上;
二是连接两个或多个文件,如“cat f1 f2 > f3”将把文件f1和f2的内容合并起来,然后通过输出重定向符“>”,将它们放入文件f3中。
示例
cat f - g 先输出f 的内容,然后输出标准输入的内容,最后输出g 的内容。
cat 将标准输入的内容复制到标准输出。
【设m1和m2时当前目录下的两个文件】
$ cat m1 (在屏幕上显示文件m1的内容)
$ cat m1 m2 (同时显示文件m1和m2的内容)
常用选项
-A, --show-all
equivalent to -vET
等价于 -vET
-b, --number-nonblank
number nonempty output lines, overrides -n
从1开始对所有非空输出行编号,覆盖 -n
-e equivalent to -vE 等价于 -vE
-E, --show-ends
display $ at end of each line
在每行结束处显示 $
-n, --number
number all output lines
从1开始对所有输出行编号
-s, --squeeze-blank
suppress repeated empty output lines
将多个相邻的空行合并成一个空行
-t equivalent to -vT 与-vT 等价
-T, --show-tabs
display TAB characters as ^I
将Tab显示为^I
-u (ignored) (被忽略)
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
除了LFD和 TAB 之外使用^ 和M- 引用
--help display this help and exit 显示此帮助信息并退出
--version output version information and exit 显示版本信息并退出
注意
当文件较大时,文本在屏幕上迅速闪过(滚屏),用户往往看不清所显示的内容,因此一般用more等命令分屏显示。为了控制滚屏,课用Ctrl+S键,停止滚屏;Ctrl+Q键,回复滚屏;Ctrl+C键(中断),可以终止命令的执行,并且返回shell提示符状态。
tac 是将 cat 反写过来,所以它的功能就跟 cat 相反,cat 是由第一行到最后一行连续显示在屏幕上,而 tac 则是由最后一行到第一行反向在屏幕上显示出来
2、more
NAME
more - file perusal filter for crt viewing 适合屏幕查看的文件阅读输出工具。
SYNOPSIS
more [options] file... more [选项] <文件>...
常用选项
-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.
在每屏的底部显示以下更友好的提示信息:
--更多--(21%)[Press space to continue, 'q' to quit.]
当用户按键有错误时,则显示[Press 'h' for instructions.]信息,而不是简单报警。
-l Do not pause after any line containing a ^L (form feed). 屏蔽换页 [^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 page.
不滚动,显示文本并清理行末。注意这个页面上的选项是自动切换的。
-c Do not scroll. Instead, paint each screen from the top, clearing the remainder of each
line as it is displayed.
不滚动,清除屏幕并显示文本,从顶部绘制每个屏幕,在显示时清除每行的剩余部分。
-s Squeeze multiple blank lines into one. 将文件中连续的空白行压缩成一个空白行显示
-u Suppress underlining. 把文件内容中的下画线去掉
-number
The screen size to use, in number of lines.
指定一个整数num,表示一屏显示多少行
+number
Start displaying each file at line number.
从指定行开始显示文件
+/string
The string to be searched in each file before starting to display it.
从匹配搜索字符串的位置开始显示文件
说明
more命令是一个基于vi编辑器的文本过滤器,以全屏幕形式显示文件内容。
more命令一次显示一瓶文本(file文件),满屏后停下来,并且在屏幕底部出现一个提示信息,给出至今已显示的该文件的百分比“--更多--(xx%)”。
可以用下列不同的方法对提示作出回答:
- 按Space键,显示文本的下一屏内容。
- 按Enter键,只显示文本的下一行内容。
- 按“/”键,接着输入一个模式,可以在文本中寻找下一个相匹配的模式。
- 按h键或?键,显示帮助屏,其中有相关的帮助信息。
- 按B键或^B,显示上一屏内容。
- 按Q键,退出more命令。
示例
1、显示文件mfile的内容,在显示之前先清屏,并在屏幕下方显示完整的百分比。
$ more -dc mfile
2、显示文件mfile的内容,每10行显示一次,而且在显示之前先清屏。
$ more -c -10 mfile