Linux: Append Line to End of File
This post will guide you how to append line to end of file in Linux. how do I append text to th end of a file without an editor in Linux system. How to append or add text to a file in Linux. How to append multiple lines to end of a file in Linux.
Append Line to End of File
To append a line to end of a file in Linux, you need to use the redirection character to append text or line to end of the file. you should be noticed that you must use the double redirection characters.
For example, you want to append text to end of file fio.tmp, just type the following command:
#echo "this is a text" >> fio.tmp
Append Multiple Lines to end of a File
If you want to append multiple lines to end of a file at the same time in Linux, you can refer to the following examples:
cat << EOT >>fio.tmp line1 line2 EOT
This example will expand two lines (line1 and line2) to end of the file fio.tmp at the same time.
Or you can also use the following command to expand multiple lines to a file:
#echo "line1 \nline2 \n" >>fio.tmp
You can also execute printf command to expand multiple lines to a file:
#printf '%s\n %s\n' 'line1' 'line2' >>fio.tmp
Append Standard Output and Standard Error Ouput to end of File
If you want to append standard output and standard error ouput to end of a file, you need to use the & character in combination with >> character in Linux. Like this:
#echo "this is a text" &>>fio.tmp
Or
#echo "this is a text" >>fio.tmp 2>>&1