Creating and editing a file via SSH

There are a few different ways to create and edit a file when logged into a DreamHost server via SSH. This article explains how to use two text editors:

  • nano — Best choice for beginners
  • vim — More features than 'nano', but also more difficult to use. 'vim' is a good choice for advanced users

If you're not comfortable editing files in a terminal, view the following article:

Using 'nano' to create and edit a file

'nano' is easier to use than 'vim' so it's a good choice for newer users. Follow the steps below to create and edit a file using 'nano'.

Creating or editing a file using 'nano'

  1. Log into your server via SSH.
  2. Navigate to the directory location you want to create the file, or edit an existing file.
  3. Type in nano followed by the name of the file. For example, if you wish to create (or edit) a new file name index.html, run the following:
    [server]$ nano index.html
    A new file opens named index.html:
    nano 01.png
  4. Start typing your data into the file.
  5. When you're ready to save the file, hold down the Ctrl key and press the letter 'O' (Ctrl + O).
    The bottom of the prompt asks you to confirm the name of the file, which is already set as 'index.html':
    nano 02.png
  6. Click 'Enter' to save.
  7. When finished, click Ctrl + X to close 'nano' and return to your shell.

Using 'vim' to create and edit a file

As stated above, 'vim' includes more features to edit files, but is also more difficult to learn. 'vim' is only recommended for advanced users with prior experience working in the Linux shell.

Using 'vim' to create and edit a file

  1. Log into your server via SSH.
  2. Navigate to the directory location you wish to create the file, or edit an existing file.
  3. Type in vim followed by the name of the file. For example, if you wish to create (or edit) a new file named test.html, run the following:
    [server]$ vim test.html
    The 'vim' editor may appear confusing at first because you cannot type into the file yet:
    vim 01.png
  4. Click the letter 'i' on your keyboard to enter INSERT mode in 'vim'.
    It now shows -- INSERT -- on the bottom left:
    vim 02.png
  5. Start typing into the file.
  6. When finished editing the file, click the ESC key. This takes you out of INSERT mode and -- INSERT -- disappears from the bottom left of your terminal.
  7. To save the file, type in a colon followed by wq. For example:
    :wq
    The characters :wq appear on the bottom left:
    vim 03.png
  8. Click 'Enter' to save.

See also

Did this article answer your questions?

Article last updated .