【Linux】Cat命令用法详解

来源:互联网 发布:徐千雅最新网络歌曲 编辑:程序博客网 时间:2024/06/05 04:47

cat: concatenate 连接,连锁,意思是合并文件,cat还能在屏幕上显示文件的内容

该命令主要是对文档内容进行添加,

范例: 
把 textfile1 的档案内容加上行号后输入 textfile2 这个档案里 
cat -n textfile1 > textfile2 
把 textfile1 和 textfile2 的档案内容加上行号(空白行不加)之后将内容附加到 textfile3 里。 
cat -b textfile1 textfile2 >> textfile3 
cat /dev/null > /etc/test.txt 此为清空/etc/test.txt档案内容 
cat 也可以用来制作 image file。例如要制作软碟的 image file,将软碟放好后打 
cat /dev/fd0 > OUTFILE 
相反的,如果想把 image file 写到软碟,请打 
cat IMG_FILE > /dev/fd0 

使用权限:所有使用者 
使用方式:cat [-AbeEnstTuv] [--help] [--version] fileName 
说明:把档案串连接后传到基本输出(萤幕或加 > fileName 到另一个档案)
参数:
-n 或 --number 由 1 开始对所有输出的行数编号
-b 或 --number-nonblank 和 -n 相似,只不过对于空白行不编号
-s 或 --squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行
-v 或 --show-nonprinting
通用范例:
cat -n textfile1 > textfile2 把 textfile1 的档案内容加上行号后输入 textfile2 这个档案里
cat -b textfile1 textfile2 >> textfile3 把 textfile1 和 textfile2 的档案内容加上行号(空白行不加)之后将内容附加到 textfile3 里。 

注: 
1. OUTFILE 指输出的 image 档名。 
2. IMG_FILE 指 image file。 
3. 若从 image file 写回 device 时,device 容量需与相当。 
4. 通常用在制作开机磁片。 

13.9. 使用 cat 来操作文件

0 0
原创粉丝点击