How to Append Multiple Lines to a File from Terminal in Ubuntu
Topic: Ubuntu / LinuxPrev|Next
Answer: Use the echo Command
You can use the echo command to append multiple lines to a file using command line in Ubuntu.
For example, if your current working directory is /var/www and you want to append multiple lines to a text file named sample.txt inside of it, you can do something like this:
Twinkle
Little Star" >> sample.txt
Alternatively, you can provide the absolute path of the file like this:
Twinkle
Little Star" >> /var/www/sample.txt
Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash / is an absolute path.
You can also use the cat command to perform the same task like this:
Twinkle
Twinkle
Little Star
EOT
In Unix terminals, EOT (End-of-Transmission) is used to indicate the end of the data stream.
Related FAQ
Here are some more FAQ related to this topic:
- How to change current working directory in Ubuntu terminal
- How to create an empty file from command line in Ubuntu
- How to open a text file in terminal in Ubuntu

