Linux每天一个命令:cat

Linux cat命令

命令:cat

cat 命令用于连接文件并打印到标准输出设备上。

使用权限

所有使用者

语法格式

cat [-AbeEnstTuv] [--help] [--version] fileName
[root@testhost]# cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.

-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

With no FILE, or when FILE is -, read standard input.

Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.

参数说明:

-n 或 --number:由 1 开始对所有输出的行数编号。

-b 或 --number-nonblank:和 -n 相似,只不过对于空白行不编号。

-s 或 --squeeze-blank:当遇到有连续两行以上的空白行,就代换为一行的空白行。

-v 或 --show-nonprinting:使用 ^ 和 M- 符号,除了 LFD 和 TAB 之外。

-E 或 --show-ends : 在每行结束处显示 $。

-T 或 --show-tabs: 将 TAB 字符显示为 ^I。

-e : 等价于 -vE。

-A, --show-all:等价于 -vET。

-e:等价于"-vE"选项;

-t:等价于"-vT"选项;

实例

把 textfile1 的文档内容加上行号后输入 testfile2 这个文档里:

[lzy@CentOS72Demo ~]$ cat testfile1 > testfile2

把 testfile1 和 testfile2 的文档内容加上行号(空白行不加)之后将内容附加到 testfile3 文档里:

[lzy@CentOS72Demo ~]$ cat -b testfile1 testfile2 >> testfile3

清空 /etc/test 文档内容:

[lzy@CentOS72Demo ~]$ cat /dev/null > testfile

cat 也可以用来制作镜像文件。例如要制作软盘的镜像文件,将软盘放好后输入:

cat /dev/fd0 > OUTFILE

相反的,如果想把 image file 写到软盘,输入:

cat IMG_FILE > /dev/fd0

  • 1. OUTFILE 指输出的镜像文件名。

  • 2. IMG_FILE 指镜像文件。

  • 3. 若从镜像文件写回 device 时,device 容量需与相当。

  • 4. 通常用制作开机磁片。

  • 5. 通常/dev/null看作"黑洞". 它非常等价于一个只写文件. 所有写入它的内容都会永远丢失. 而尝试从它那儿读取内容则什么也读不到. 然而, /dev/null对命令行和脚本都非常的有用.

 

***********************************************************

 学习永远不晚。——高尔基

***********************************************************

posted @ 2017-09-12 22:42  chengd  阅读(417)  评论(0编辑  收藏  举报