如何通过 Ubuntu 终端编辑/保存文件

这是一个非常简单的问题:

我只需要打开一个文件(这个文件名是 galfit.Feeme)。当我在目录中时,我可以使用 view galfit.Feeme 查看文件,但是我不知道如何编辑这个文件,然后保存编辑。你是怎么做到的?

490420 次浏览

Normal text editors are nano, or vi.

For example:

root@user:# nano galfit.feedme

or

root@user:# vi galfit.feedme

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

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

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.

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!