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.
Use the
echo
CommandYou 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 namedsample.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.
need an explanation for this answer? contact us directly to get an explanation for this answer