How to create a file and write content in CentOS?
To create a file and write content in a CentOS system, you can use the following command:
- Create a file:
touch filename
- Edit the file and write in the content.
vi filename
Once you’re in the Vi editor, press the keyboard letter keys “i” or “a” to enter the editing mode, then type in the content you want to write. Once you’re done, press “Esc” on the keyboard to exit the editing mode, then type “:wq” to save and exit.
- Write content using the echo command.
echo "content" > filename
This command will write the “content” to the file. To append content to the file, you can use the “>>” symbol, for example:
echo "new content" >> filename