To append text to the end of a file in Linux, you can use the echo
command followed by the text you want to append and the >>
operator to redirect the output to the file. For example:
echo "This text will be appended to the end of the file" >> file.txt
This will add the specified text to the end of the file file.txt
. If the file does not exist, it will be created.
You can also use the tee
command to append text to a file. For example:
echo "This text will be appended to the end of the file" | tee -a file.txt
This will append the output of the echo
command to the file file.txt
. The -a
option tells tee
to append the output to the file rather than overwriting it.
Both of these commands can be used in a script or at the command line.