首页 > 代码库 > 基础命令之cat

基础命令之cat

功能说明

 

cat用来查看文件内容,创建文件,文件合并,追加文件内容等功能

cat - concatenate files and print on the standard output

Concatenate FILE(s), or standard input, to standard output

令格式

cat [OPTION]... [FILE]...

说明:

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

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

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

把档案串连接后传到基本输出(屏幕或加 > fileName 到另一个档案)Concatenate FILE(s), or standard in

 

命令功能

cat - concatenate files and print on the standard output

Concatenate FILE(s), or standard input, to standard output

使用范例

一次显示整个文件

[root@localhost ouyan]# cp /etc/passwd /home/ouyan

[root@localhost ouyan]# cat passwd

从键盘创建一个文件

root@localhost ouyan]# cat >test

编辑完成后,按CTRL+D结束输入,只能创建文件,不能编辑已有的文件

将几个文件合并为一个文件

[root@localhost ouyan]# ls

a b c passwd test test2

[root@localhost ouyan]# cat test test2 >test3

[root@localhost ouyan]# ls

a b c passwd test test2 test3

把 linuxfile1 的档案内容加上行号后输入 linuxfile2 这个档案里

cat -n linuxfile1 > linuxfile2

cat /dev/null > /etc/test.txt 此为清空/etc/test.txt档案内容

cat > test.sh << EOF 内容 EOF文本结束符

基础命令之cat