What's the difference between using > and >> in shell?

后端 未结 6 2010
温柔的废话
温柔的废话 2021-01-14 07:07

I\'ve seen somewhere that we can use >> in shell. What\'s the difference between using > and >> in shell?

6条回答
  •  猫巷女王i
    2021-01-14 07:32

    When you use >, as in:

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

    The > operator will completely overwrite any contents of the file output.txt if it exists. If the file does not exist, it will be created with the contents "this is a test."

    This usage:

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

    Will add the link "this is a test" to any content in output.txt (called 'appending'). If the file does not exist, it will be created, and the text will be added.

提交回复
热议问题