Cách 1: Sử dụng lệnh nano để edit file
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:- Open Nano by typing the following:
nano
- Enter the information to wish to put in the file.
- Save the file (keystroke listed above).
- Enter the name of the file.
- Press Enter.
To edit an existing file using Nano, please follow these steps:- Open Nano by typing the following:
nano filename
- Edit the information in the file.
- Save the file (keystroke listed above).
- 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.