How to edit/save a file through Ubuntu Terminal

FileUbuntuTerminalSaveEdit

File Problem Overview


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?

File Solutions


Solution 1 - File

Normal text editors are nano, or vi.

For example:

root@user:# nano galfit.feedme

or

root@user:# vi galfit.feedme

Solution 2 - File

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

Solution 3 - File

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

There are two ways to do it -

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.

Solution 4 - File

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

Solution 5 - File

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvdogsandmanView Question on Stackoverflow
Solution 1 - FileNick Anthony ParutaView Answer on Stackoverflow
Solution 2 - FileAbhishek GuptaView Answer on Stackoverflow
Solution 3 - FileRavistmView Answer on Stackoverflow
Solution 4 - FileHarryView Answer on Stackoverflow
Solution 5 - FileNadeem QasmiView Answer on Stackoverflow