Search the VMware Knowledge Base (KB)
View by Article ID

Editing files on an ESX host using vi or nano (1020302)

  • 19 Ratings

Purpose

This article provides steps for editing files on an ESXi\ESX host by using vi or nano.

Resolution

 
These steps can be used on an ESX 3.x or 4.x host. 

Run an SSH session to your ESX host using SSH as the user root. If you have not established an SSH session to your ESX host yet, see Connecting to an ESX host using a SSH client (1019852).

You can also use these instructions after accessing the ESX host console directly or through a remote KVM, then pressing ALT+F1 and logging in as root.

To see what is in the file you can use the cat command to display the contents of, for example /etc/hosts, on the screen.

The output appears similar to:

<localhost> localhost
::1 localhost
<IPAddress> <FQDN>

Note
: If you want to have a backup of this file prior to editing it, make a copy of it in /var/tmp. To make a copy, type cp /etc/hosts /var/tmp and press Enter.

Editing using vi

To add an entry for another ESXi\ESX host at IP <IPaddress> and FQDN into the /etc/hosts file using vi:
  1. Type vi /etc/hosts and press Enter. Now you are in the vi text editor. You can move around using page up, page down, and the arrow keys.
  2. Move down to the last line in the file.
  3. Enter insert mode.

    You can press i to start editing where the cursor is, you can also press shift+o to start editing on a new line above the cursor, or o to start editing on a new line below the cursor.

    You see -- INSERT -- at the bottom of the vi window while you are in insert mode within vi.

  4. Add your entry.

    Note: The number pad on the keyboard does not work within vi by default. Use the numbers above the letters on your keyboard. You can use the arrow, backspace, and delete keys as well as enter text while in edit mode.

  5. To quit and save changes press Esc, :, w, q, then press Enter.

    If you decide you are not comfortable with the changes and want to quit without saving, press Esc, :, q, then press Enter. You do not have to press Esc, :, and q at the same time.
To edit an entry using vi:
  1. Type vi /etc/hosts and press Enter.
  2. Without entering insert mode move to the character you want to change, press R, then press the key for the character you want to change to.
  3. To save and quit press Esc, :, w, q.

    Note: You may receive a warning indicating that the file is read only when you try to save and quit. To get around this, add an ! character to the end of the Esc, :, w, q sequence and press Enter.
    Note: If you are using putty and you are in insert mode, you can paste clipboard items into vi by left-clicking copied text.
To delete the entries using vi:
  1. Type vi /etc/hosts and press Enter to edit the file.
  2. Arrow down to the line to delete.
  3. Press twice to delete the whole line. You can also pressto delete only one character at a time when you are not in insert mode.

Editing using nano

Note: Nano is not available in ESXi.
 
To edit a file using nano:
  1. Type nano /etc/hosts and press Enter. At the bottom of the nano window there are commands with a ^ character in front, which indicates you need to press and hold Ctrl and the character to run the command. For example, to Exit you press and hold Ctrl and press X.
  2. To make an entry arrow down to the place where you want to begin entering the text.

    Note
    : The number pad does not work by default. Pressing Num Lock actually opens help by default. Use the numbers above the letters on your keyboard.

  3. In nano, you do not need to enter and leave insert mode, you can just start editing.
  4. To Save and Quit, press Ctrl+X. You see the option to Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES)? Then the option for Y YES, N NO or ^C
    Cancel.

    Press Y to save. You can see a File Name to Write: /etc/hosts prompt. Save the file with another file name, but press Enter to save to /etc/hosts. The changes have been applied and saved.
Note: You can copy multiple items into the clipboard and paste them into nano to simplify bulk edits. Always copy and paste from a text editor like Notepad to ensure you are working with plain text.

Additional Information

Preferred Editors

There are different editors to choose from, depending on your running platform. The following is non-exhaustive list of editors available in different platforms:
  • VMware ESX includes the open source terminal-based editors nano and vi. For more information, see the vi man pages or the nano man pages.
  • VMware ESXi includes the open source terminal-based editor vi. For more information, see the vi man pages.
  • Windows-based machines include basic text editors such as Notepad and Wordpad. If you are using either of these text editors, you must ensure that you are saving files in their original format and encoding.
Notes:
  • The editors available in the shell (vi or nano) are meant for troubleshooting purposes only and must be used only when directed by VMware. The vSphere Client, vCLI, and PowerCLI should be the primary method of propagating changes to your ESX/ESXi host.
  • Notepad saves documents as ANSI text which may not be the same file format as the files downloaded from a VMware ESX or ESXi host. For more information, see Using different language formats in Notepad from Microsoft's Windows XP Professional Product Documentation.

Note: The preceding links were correct as of September 22, 2014. If you find the links are broken, please provide feedback and a VMware employee will update the link.

See Also

Update History

06/27/2011 - Added background information about different editors.

Request a Product Feature

To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.

Feedback

  • 19 Ratings

Did this article help you?
This article resolved my issue.
This article did not resolve my issue.
This article helped but additional information was required to resolve my issue.

What can we do to improve this information? (4000 or fewer characters)




Please enter the Captcha code before clicking Submit.
  • 19 Ratings
Actions
KB: