118k views
1 vote
Whats the difference between > and >> when redirecting stdout/stderr?

User Rhys Towey
by
7.3k points

1 Answer

3 votes

Final answer:

The difference between > and >> when redirecting stdout/stderr is that > overwrites the file if it exists, while >> appends to the file if it exists.

Step-by-step explanation:

> is used to redirect the standard output (stdout) of a command to a file, but if the file already exists, it will be overwritten. The difference between > and >> when redirecting stdout/stderr is that > overwrites the file if it exists, while >> appends to the file if it exists. On the other hand, >> appends the stdout to the end of the file if it already exists.

For example, if we have a command like echo 'Hello, World!' > output.txt, it will create a new file called 'output.txt' and write the output into it. But if we use echo 'Hello, Again!' >> output.txt, it will append the new output to the existing 'output.txt' file, instead of overwriting it.

User Wizard Of Kneup
by
8.5k points