WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

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:

echo "Twinkle
Twinkle
Little Star" >> sample.txt

Alternatively, you can provide the absolute path of the file like this:

echo "Twinkle
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:

cat <<EOT >> /var/www/sample.txt
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:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties