Linux Writing multiple lines to a file from command line

Hi Guys,

We learn something new everyday. I did too. I know I am a late learner but its better late than never.

 

I asked myself a question about how to write multiple lines using say echo to a file.

I generally will open my vi editor and and write something there and then save my file.

and when I am using echo I never really had that situation where I need to write multiple lines to a file. But things changed 🙂

Normally I will do something like this

 

Above will write word hello to file named test.txt in your current directory

 

 

Let me show you how to write multiple lines

Trick is when you start you echo command follow it with ” (double quotes) and don’t close them until you are finished with your sentense as shown below

Above will write “Sit lectus dis placerat non aenean ultrices. Tempor, amet nisi in arcu, amet turpis, cras mattis ultrices, enim, penatibus. ” 

to your test.txt file.

I hope this helps

Cheers

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.