How to edit/save a file through Ubuntu Terminal

六月ゝ 毕业季﹏ 提交于 2019-11-30 10:12:59

问题


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?


回答1:


Normal text editors are nano, or vi.

For example:

root@user:# nano galfit.feedme

or

root@user:# vi galfit.feedme



回答2:


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



回答3:


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.




回答4:


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




回答5:


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!


来源:https://stackoverflow.com/questions/17535428/how-to-edit-save-a-file-through-ubuntu-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!