What is the difference between > and >>?

093

The difference between > and >> in the terminal relates to how they handle file output redirection:

  1. > (Overwrite Redirection):

    • This operator is used to redirect output to a file, creating the file if it does not exist or overwriting it if it does.
    • Example:
      echo 'Hello' > file.txt
      If file.txt already contains data, it will be replaced with "Hello".
  2. >> (Append Redirection):

    • This operator is used to append output to the end of a file, creating the file if it does not exist.
    • Example:
      echo 'World' >> file.txt
      If file.txt already contains data, "World" will be added to the end of the existing content without deleting anything.

In summary, use > to overwrite a file and >> to append to a file.

0 Comments

no data
Be the first to share your comment!