How to save the output of a Linux/Unix command to a file

The Bash / KSH and POSIX shell provides a file redirection option to redirect the output of commands to a file using the following two operators

> is output redirection symbol
>> is append output redirection symbol


The > operator always overwrites existing output files

Syntax to save the output of a command to a file

 command > filename  

Example

Saving the date command output to a file called output.txt

 $ date > output.txt  

In this example, save the output of the date command to a file called output.txt

The >> operator appends the output of a command with the same file as

Syntax to save and append the output of a command to a file

 command >> filename  

Example

Saving and appending the date command output to a file called output.txt

 $ date >> output.txt  

Nikunj K

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.