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:

  1. Create a file:
touch filename
  1. 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.

  1. 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
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds