What is the difference between using> and >> in a shell?

I saw somewhere that we can use → in the shell. What is the difference between using> and → in a shell?

+3
source share
6 answers

>>intended to be added, while >intended to be written (replaced).

+10
source

If the file exists, >>will be added to the end of the file, >overwrite it.

Both will create it otherwise.

+5
source

, , , :

> (.. ) .

>> .

+4

' → ' , ' > ' . :

# cat test
test file
# echo test > test
# cat test
test
# echo file >> test
# cat test
test
file
+1

> , :

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

p > 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
0

Source: https://habr.com/ru/post/1725893/


All Articles