MilesWeb
USA’s #1 Web Hosting Company Since 2012
Award-winning Web Hosting Company
Everything that you need to build, host and manage a website is available at just 60/mo

How to Create and Edit a File via SSH?

You can create and edit a file when logged into a MilesWeb server via SSH. This article explains the use of two text editors:

nano — Best for beginners.
vim — Offers more features than ‘nano’, but also difficult to use. It is a good choice for advanced users.

Note: If you don’t want to edit files in a terminal, you can check the below article:

How to Create and Edit a File via FTP?

Create and Edit a File Using ‘nano’

‘nano’ is the best choice for newbies as it is easier to use than ‘vim’. Check the steps below to create and edit a file using ‘nano’.

1. Log into your server using SSH.

2. Go to the directory location where you want to create the file, or edit an existing file.

3. Type nano along with the name of the file. For example, if you want to create (or edit) a new file named as index.html, run the following:

You will see a new file open with the name index.html as below:

4. Now, you can type your data into the file.

5. After you complete typing the data, save the file and hold down the Ctrl key and press the letter ‘O’ (Ctrl + O).

You will be prompted to confirm the file name that is already set as ‘index.html’ as below:

6. Next, click the ‘Enter’ key on your keyboard for saving the file.

7. Then, click Ctrl + X to close ‘nano’ and go back to your shell.

Create and Edit a File Using ‘vim’

1. Log into your server using SSH.

2. Go to the directory location where you want to create the file, or edit an existing file.

3. Type in vim along with the name of the file. For example, if you want to create (or edit) a new file named as test.html, run the following:

The ‘vim’ editor will get displayed which might seem to be confusing at first as you won’t be able to type into the file yet:

4. On the keyboard, click the letter ‘i’ to enter INSERT mode in ‘vim’.

You will now see — INSERT — on the bottom left:

5. Type the data into the file now.

6. After you are done with editing the file, click the ESC key. You will be taken out of INSERT mode and — INSERT — will get disappeared from the bottom left of your terminal.

7. Save the file by typing in a colon followed by wq as below:

You will see :wq appeared on the bottom left:

8. Now, on your keyboard click the ‘Enter’ key to save.

Changing the Name of a File

If you wish to change the name of a file, use the mv command. For example, a file named ‘file1.txt’ changes to ‘file2.txt’.

That’s it! You can now create and edit a file via SSH.

Pallavi Godse

Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.

Leave a Reply

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