Understanding Output Redirection
Think of output redirection as a way to save what you see on the screen into a file instead. It’s like taking a screenshot of text and putting it in a file.
>: Saves output to a file, replacing existing content.
>>: Adds output to a file without deleting what's already there.
For example, if you have a command some_command and you want to save its result into a file named “output.txt”:
$ some_command > output.txt
To add the result of some_command to the end of an existing file:
$ some_command >> output.txt
Write to a File From the Shell
Writing files in the shell might sound complex, but it’s simple, and once you understand it will be at your fingertips. Whether you’re saving data, creating files, or editing existing ones, here’s a simple guide to help you with file writing in the shell. This article makes you aware of everything and guides you to understand each and everything.