Ads

Tuesday, 9 June 2015

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