103

This is quite a simple question:

I just need to open a file (this filename is galfit.feedme). I can view the file with view galfit.feedme when I'm in the directory, but I do not know how to edit this file and then save the edit. How do you do that?

vdogsandman
  • 5,289
  • 8
  • 21
  • 21

5 Answers5

137

Normal text editors are nano or vi.

For example:

root@user:# nano galfit.feedme

or

root@user:# vi galfit.feedme
John Smith
  • 7,243
  • 6
  • 49
  • 61
Nick Anthony Paruta
  • 1,386
  • 1
  • 9
  • 3
80

For editing use

vi galfit.feedme //if user has file editing permissions

or

sudo vi galfit.feedme //if user doesn't have file editing permissions

For inserting

Press i //Do required editing

For exiting

Press Esc

    :wq //for exiting and saving
    :q! //for exiting without saving
nidhi0806
  • 343
  • 3
  • 14
Abhishek Gupta
  • 4,066
  • 24
  • 27
20

If you are not root user then, use following commands:

There are two ways to do it -

1.

sudo vi path_to_file/file_name

Press Esc and then type below respectively

:wq //save and exit
:q! //exit without saving
  1. sudo nano path_to_file/file_name

When using nano: after you finish editing press ctrl+x then it will ask save Y/N.
If you want to save press Y, if not press N. And press enter to exit the editor.

Ravistm
  • 2,163
  • 25
  • 25
6

Open the file using vi or nano. and then press " i " ,

For save and quit

  Enter Esc    

and write the following command

  :wq

without save and quit

  :q!
Nadeem Qasmi
  • 2,217
  • 22
  • 16
  • 2
    This doesn't seem to say anything that hasn't already been said in [this answer](https://stackoverflow.com/a/22909944/19068) except you advise people to use nano where those keyboard commands **won't work**. – Quentin Apr 01 '19 at 14:13
4

Within Nano use Ctrl+O to save and Ctrl+X to exit if you were wondering

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
Harry
  • 61
  • 1