Question
How do you edit a file on the command line?
Answer
The procedure below will show you how to edit a file on the command line using the vi/vim and nano commands.
Note: "/path/to/file" must be replaced with the full path to the file to be edited.
Vi/Vim
Open the file in the editor:
# vi /path/to/file
- Press the
ikey to enter insert mode. Make your desired changes.
Note: The arrow keys can move around in the file.
- Press the escape
Esckey to exit insert mode. - Type
:wand press theEnterkey to save your changes. Type
:qand press theEnterkey to close the file.Note: You can abort any unintentional changes by using :q! instead of :w. This will close Vi without saving the file.
Nano
Open the file in the editor:
# nano /path/to/file
Make your desired changes.
Note: The arrow keys can move around in the file.
- Press the
Ctrl + Xkeys to close the file. - Press the
ykey to save your changes. - Press
Enterto exit.
Comments
0 comments
Article is closed for comments.