You can append text to the end of a file in Linux using the echo
command and the >>
operator. The echo
command outputs the specified text, and the >>
operator appends the output to the end of the specified file.
Here’s an example of how to append text to the end of a file named file.txt
:
echo "This is the text that will be appended." >> file.txt
In this example, the text "This is the text that will be appended."
will be appended to the end of the file file.txt
. If the file file.txt
does not exist, it will be created.
You can also append text to the end of a file using the tee
command and the -a
option. The tee
command outputs the specified text to both the console and a file. The -a
option tells tee
to append the output to the end of the file, rather than overwriting the file.
Here’s an example of how to append text to the end of a file named file.txt
using the tee
command:
echo "This is the text that will be appended." | tee -a file.txt
This example works similarly to the previous one, but it uses the tee
command instead of the echo
command and >>
operator.