Cách 1: Sử dụng lệnh nano để edit file



The following article explains how to edit a file using Nano. This first requires you to establish an SSH connection to your server.
Nano uses keystroke combinations to execute certain functions. The keystrokes consist of first pressing and holding the control key and then pressing an additional key. The following are common functions:
  • CTRL+o: this will save the file
  • CTRL+x: this will exit the file
  • CTRL+w: this will allow you to enter a phrase to search the file
  • CTRL+k: this will allow you to cut 1 or more lines of text
  • CTRL+u: this will allow you to uncut lines of text that were cut using CTRL k (similar to pasting text)
  • CTRL+v: this will advance the file to the next page
  • CTRL+y: this will move the file to the previous page
  • CTRL+t: this will run spellcheck on the file

To create a new file using Nano, please follow these steps:

  1. Open Nano by typing the following:
    nano
  2. Enter the information to wish to put in the file.
  3. Save the file (keystroke listed above).
  4. Enter the name of the file.
  5. Press Enter.

To edit an existing file using Nano, please follow these steps:

  1. Open Nano by typing the following:
    nano filename
  2. Edit the information in the file.
  3. Save the file (keystroke listed above).
  4. Press Enter to save the file with the same name.


Cách 2: Sử dụng lệnh vi để edit file





Expertise level: Easy

VI is a text editor that can edit most of the files under a Linux architecture (text files, php, etc.).

To open a file in VI editor, type the following:

vi FileName


For a file named test.txt, it would b:

vi test.txt


Once the file has been opened, press the "insert" key on your keyboard to enter edit mode.
The "Esc" key will allow you to leave the edit mode, but not the VI editor.

Here is the list of frequently used commands necessary to use the VI editor:



  • :q! : Forces the editor to exit without saving.
  • :w : Saves the changes that have been made to the file.
  • :wq : Saves the changes that have been made to the file and then exits.
  • :# : Where # is a number - Brings you to line number #
  • :$ : Brings you to the last line of the file
  • :0 : Brings you to the first line of the file
  • :/word : This will search for the string "word" in the file. By pressing "n" you can view the other search result.

For more information about vi (and vim), please consult the following website: http://www.vim.org/docs.php