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

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


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

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


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!