Languages
[Edit]
EN

Bash - write output to text file (overwrite)

0 points
Created by:
Pearl-Hurley
559

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.

 

See also

  1. Bash - append output at the end of text file

Alternative titles

  1. Bash - write command output to text file
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join