保持快乐,善于表达,敢于创新

cat命令

上一篇 / 下一篇  2009-06-23 17:25:23 / 个人分类:Shell编程

范例:
cat -n textfile1 > textfile2 把 textfile1 的档案内容加上行号后输入 textfile2 这个档案里
cat -b textfile1 textfile2 >> textfile3 把 textfile1 和 textfile2 的档案内容加上行号(空白行不加)之后将内容附加到 textfile3 里。
范例:
把 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
注:
1. OUTFILE 指输出的 image 档名。
2. IMG_FILE 指 image file。
3. 若从 image file 写回 device 时,device 容量需与相当。
4. 通常用在制作开机磁片。

        当你使用重导向标准输入符号 < 时,你是在告诉 shell 你想使用某个文件作为命令的输入。使用一个你已创建的文件来演示这一概念。键入: cat < sneakers.txt因为你用来分隔 cat 命令和文件的是小于号(<),sneakers.txt 的输出就被 cat 命令读取
        linux下cat命令编辑文本
cat >> file ,然后一行一行的输入就可以了,按Ctrl+C退出,也可以用cat >> file << delimiter 所谓delimiter就是分隔符,编辑文本时,如果输入的一行等于delimiter,编辑文本就结束,如下

$:cat >> test.txt <

>aaaa

>bbb

....

>end

$:

碰到end,编辑自动结束!

总结cat命令的功能主要包括:
1.读取文件,在屏幕上显示整个文件的内容;
2.合并文件cat filea,fileb>filec;
3.cat的输出重导向文件(>);
4.给文件添加信息(>>);
5.编辑文本cat >> filea (或cat >> file << delimiter );
5.重导向标准输入(< )。


相关阅读:

TAG: cat Cat

 

评分:0

我来说两句

Open Toolbar