The echo
command is used to print some text into the terminal or console or command line interface. The echo command prints provided text into the standard output which is the current terminal or console or command line interface. But we can use the echo command output in a file in Linux.
Write Into File
We can use the echo
command in order to output into a file. We provide the text or data we want to write into the file. It is better to use double quotes in order to prevent mistakes. In the following example, we write “Hello Linuxtect” into the file named data.txt .
$ echo "Hello Linuxtect" > data.txt
Append Into Existing File
We can also append some data to the existing file by using the echo command. The >>
is used to redirect data into the existing file. Provided text or data is applied to the last line of the file. In the following example, we append “Hello Linuxtect” into the file named data.txt .
$ echo "Hello Linuxtect" >> data.txt