How to Open and edit File in Linux

There are a few different ways to create and edit a file in Linux command line. This article explains how to use two text editors: nano and vim

  • nano — Best choice for beginners
  • vim — More features than nano, but also more difficult to use.

In using nano, type the following command:

$ sudo nano file_name

This will open the file and you can edit it. you can close the file and save it by:

Pressing CTRL+X at the same time then press Y to save it and hit ENTER.

In using vim, type the following command:

$ vi file_name

This will only open the file. In order to edit it:

Press I key, then change what you have to change in the file. Press ESC to stop editing then to save the file, type :wq! then ENTER.

Leave a Comment

Your email address will not be published. Required fields are marked *