Junior — Middle
What is the difference between the '>' and '>>' operators when working with files in Linux command line?
sobes.tech AI
Answer from AI
In Linux, when working with files in the command line:
-
The
>operator is used to redirect the output of a command to a file, overwriting the file's contents. -
The
>>operator also redirects output, but appends (adds) it to the end of the file without deleting existing data.
Example:
# Overwrite the file output.txt with the result of the ls command
ls > output.txt
# Append the result of the date command to the end of output.txt
date >> output.txt
Thus, > is for creating or replacing a file, >> is for adding to existing content.