2009-12-16 110 views

回答

10

>>用于追加,而>用于写入(替换)。

+0

会是什么的一个例子>>? – goe 2009-12-16 20:50:32

+0

是的,当你使用>时要小心,因为如果文件已经存在,它将完全覆盖文件,而如果没有文件,或者它会创建一个新文件,或者开始追加到现有文件的末尾。 – 2009-12-16 20:51:11

+1

@goe:你会使用'>>'继续在文件末尾添加一行。例如,一个日志文件。 – 2009-12-16 20:52:05

4

是有区别的,如果你重定向到文件已经存在:

>截断(即替换)现有文件。

>>附加到现有文件。

5

如果文件存在,>>将追加到文件末尾,>将覆盖它。

两者都会创建它。

+0

+1既完整又简洁。 – wallyk 2009-12-16 20:53:24

1

'>>'会让你追加数据到一个文件,其中'>'将覆盖它。例如:

# cat test 
test file 
# echo test > test 
# cat test 
test 
# echo file >> test 
# cat test 
test 
file 
0

当您使用>,如:

$ echo "this is a test" > output.txt

>运算符将完全如果存在覆盖该文件output.txt中的任意内容。如果该文件不存在,则会创建内容为“这是一个测试”。

这个用法:

$ echo "this is a test" >> output.txt

将添加链接 “这是一个测试” 在output.txt的任何内容(称为 '附加')。如果文件不存在,它将被创建,文本将被添加。

0

在这里添加更多的知识。

我们也可以使用tee命令来执行相同的:

cat newfile | tee filename - rewrites/replaces the file with new content in filename 
cat newfile | tee -a filename - appends to the existing content of the file in filename file 
+1

双用无用猫。 – Jens 2012-05-30 20:00:30

相关问题