How to Append Multiple Lines to a File from Terminal in Ubuntu
Answer: Use the
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:
Little Star" >> sample.txt
Alternatively, you can provide the absolute path of the file like this:
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:
In Unix terminals, EOT (End-of-Transmission) is used to indicate the end of the data stream.
Here are some more FAQ related to this topic: