1. 详情
Linux系统中有很多个用于查看文件内容的命令,每个命令又都有自己的特点,比如这个cat
命令就是用于查看内容较少的纯文本文件的。cat
这个命令也很好记,因为cat
在英语中是“猫”的意思,小猫咪是不是给您一种娇小、可爱的感觉呢?
注意:当文件内容较大时,文本内容会在屏幕上快速闪动(滚屏),用户往往看不清所显示的具体内容。因此对于较长文件内容可以按Ctrl+S
键,停止滚屏;以及Ctrl+Q
键可以恢复滚屏;而按Ctrl+C
(中断)键则可以终止该命令的执行。或者对于大文件,干脆用more
命令吧!
语法格式:cat [参数] [文件]
常用参数:
参数 | 描述 |
---|---|
-n | 显示行数(空行也编号) |
-s | 显示行数(多个空行算一个编号) |
-b | 显示行数(空行不编号) |
-E | 每行结束处显示$符号 |
-T | 将TAB字符显示为 ^I符号 |
-v | 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外 |
-e | 等价于”-vE”组合 |
-t | 等价于”-vT”组合 |
-A | 等价于 -vET组合 |
–help | 显示帮助信息 |
–version | 显示版本信息 |
2. 参考实例
- 查看文件的内容:
cat filename.txt
- 查看文件的内容,并显示行数编号:
cat -n filename.txt
- 查看文件的内容,并添加行数编号后输出到另外一个文件中:
cat -n linuxcool.log > linuxprobe.log
- 清空文件的内容:
cat /dev/null > /root/filename.txt
- 持续写入文件内容,碰到EOF符后结束并保存:
cat > filename.txt <<EOF
> Hello, World
> Linux!
> EOF
- 将软盘设备制作成镜像文件:
cat /dev/fd0 > fdisk.iso
3. 系统文档(mkdir cat)
NAME
cat - concatenate files and print on the standard output
SYNOPSIS
cat [OPTION]... [FILE]...
DESCRIPTION
Concatenate FILE(s) to standard output.
With no FILE, or when FILE is -, read standard input.
-A, --show-all
equivalent to -vET
-b, --number-nonblank
number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends
display $ at end of each line
-n, --number
number all output lines
-s, --squeeze-blank
suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs
display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version
output version information and exit
EXAMPLES
cat f - g
Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.
AUTHOR
Written by Torbjorn Granlund and Richard M. Stallman.
REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report cat translation bugs to <http://translationproject.org/team/>
COPYRIGHT
Copyright © 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
tac(1)
Full documentation at: <http://www.gnu.org/software/coreutils/cat>
or available locally via: info '(coreutils) cat invocation'