Sometimes you may be required to write or append multiple lines to a file. You can use multiple methods to write multiple lines to a file through command line in Linux system. Here are three methods described below.
You can write/append content line by line using the echo command.
echo " line 1 content" >> myfile.txt echo " line 2 content" >> myfile.txt
You can append content in multi-line command with the quoted text.
echo " line 1 content line 2 content" >> myfile.txt
This is the third and suggested option to use here documents (<<) to write a block of multiple lines text in a single command. The above methods are also useful but personally, I also use this while working.
cat >> greetings.txt <<EOL line 1 content line 2 content line 3 contentEOL