What is the difference between > and >> for output redirection?

Answer

In Linux shell, > redirects stdout to a file, overwriting the file if it already exists (or creating it): echo "hello" > file.txt. >> redirects stdout and appends to the file, preserving existing content: echo "world" >> file.txt. To redirect stderr (file descriptor 2) as well: command > out.txt 2>&1 redirects both stdout and stderr to the same file. command 2> errors.txt captures only errors. /dev/null is a special device that discards all input: command > /dev/null 2>&1 silences all output from a command.