How do I add text to a file and then find it again?

October 25, 2019 263 views
Linux Basics

I have made several files with nothing in them I want to know how to put text in.

1 Answer


There are many ways to create text files on Linux. One of the simpler examples is using echo and the operator to write to a file:

echo "Sample text here." > sample.txt

The magic part is the redirect operator, > which will add (redirect) the text displayed by echo to a file in the same directory named sample.txt.

There are also editors available on the command line, vim and nano are two popular ones:

nano sample.txt

You’d add your text then hit ctrl+x to save and exit. More handy shortcuts at the bottom of the nano screen.

Finally, you can edit text files locally on your computer then upload them using programs like sftp, scp or rsync - anything that utilizes your Linux user and SSH authentication.

rsync -a sample.txt user@dropletip:/home/username

Hope this helps - if you need additional help please tell us a little more about what you are trying to do so we can give more specific advice!

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!