Writing Text Directly
Sometimes you just want to type something directly into a file without running a command. You can do this using echo or printf.
To create a new file and write something in it:
$ echo "Hello, World!" > file.txt
If you want to add more text to the same file:
$ echo "More text" >> file.txt
Write to a File From the Shell
Writing files in the shell might sound complex, but it’s simple, and once you understand it will be at your fingertips. Whether you’re saving data, creating files, or editing existing ones, here’s a simple guide to help you with file writing in the shell. This article makes you aware of everything and guides you to understand each and everything.