Watch this video for a step by step process on 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:
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:
[server]$ nano index.html
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:
[server]$ vim test.html
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:
:wq
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’.
[server]$ mv file1.txt file2.txt
That’s it! You can now create and edit a file via SSH.