EN
Bash - write output to text file (overwrite)
0
points
In this article, we would like to show you how to write command output to text file in Bash.
Quick solution:
command_name > file_name.txt
Where:
command_name
- is name of the command that returns some output,file_name
- is name of the text file where we want to save the command output (by overwritting the whole file).
Practical example
In this example, we use echo
command that displays a line of text that is passed in as an argument. Using >
operator we "redirect" its output and write it to the file.txt
.
echo "Some text..." > file.txt
Note:
This operation will overwrite the whole content of
file.txt
. If you want to write at the end of the file, use>>
instead of>
operator.