[命令管道]cat f|tee f -|tee f清除文件内容且无回显

首先是echo aaa>foo.txt
这样就把aaa写进foo.txt里面了吧
如果接下来cat foo.txt|tee foo.txt -

这样会显示两遍foo.txt,而foo.里面的内容保持不变

那么问题来了
为什么当我运行cat foo.txt|tee foo.txt -|tee foo.txt的时候
1.无任何回显

2.foo.txt变成了一个空文件?

本来我以为的是应该会(cat foo.txt|tee foo.txt -)|tee foo.txt
这样foo.txt 就会变成它原来内容的两倍
=============更=======新===================
如果是cat foo.txt|tee foo.txt -|tee foo2.txt的话 那么foo2.txt确实变成了foo.txt的两倍

使用权限:所有使用者

使用方式: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. 通常用在制作开机磁片。

示例:

给定三个文件file1,file2,file3,其内容分别如下:

file1:

abc

file2:

def

file3:

执行cat file1 > file2后,file2里面的数据将被替换为file1中的内容了,即file2中的内容由原来的def变成了abc。

执行cat file1 >> file2后,将会在file2中原有的数据中追加file1中的内容,即file2中的内容变为:

def

abc

执行cat file1 file2 > file3后,file3中的内容变为:

abc

def

再次执行cat file1 file2 >> file3后,file3中的内容变为:

abc

def

abc

def

执行cat /dev/null > file3后,将会清空file3中的内容。