- Published on
> and >> in Bash
- Authors

- Name
- hwahyeon
> and >> : Redirection operators to save command output to a file
> : Overwrite (delete existing content and write new content)
echo "Hello" > hello.txt
Result:
- If
hello.txtdoesn't exist, it will be created - If it does exist, its content will be cleared and replaced with
"Hello"
>> : Append (add new content at the end of the file)
echo "See you again" >> hello.txt
Result:
- Adds
"See you again"as a new line at the end ofhello.txt - Keeps the existing content unchanged
Example:
ls -l > ls.txt
Explanation:
- This command runs
ls -l, which shows a detailed list of files in the current folder - Instead of printing the result in the terminal, it saves the output to a file named
ls.txt - If
ls.txtalready exists, its content will be overwritten