How to edit a file in Linux

How to edit a file in Linux

you can edit the file name in Linux in different ways. you can use nano and vim for how to edit a file in linux. All these are available in Linux distribution. E.g. ubantu, arch, debian, fedora etc.

How to edit a file in Linux using nano editor:

introduction of nano editor:

  • User interface of nano look like this.intoduction of nano editor

nano interface

  • On the top of the nano editor it tells about the version of nano and the file name.

nano editor version

  • Then in the prompt below the version number whole black screen. This is our main part where we type our commands for edit our files.

command area

  • Below of the editing area here are some shortcut keys.

short cut keys

How to edit file:

  1. Login to your web server through SSH.
  2. Navigate the directory location where you want to edit or create the file.
  3. In the command area type nano along with the file name. for example if you want to edit a file test.html then you write these lines of code:

                      [server]$ nano index.html

  1. A file is open name is test.html.

file name

  1. Now you can type your data which you want.

write your data

  1. When you have done to write your data then you can save your file by press ctrl+o.
  2. On the bottom of the prompt he asking you to write the file name. you confirm your file name test.html.
  3. Press the enter key for to save the file.
  4. When you have done your work then press ctrl+X for exit the nano.

Using ‘vim’ editor:

Vim is a good editor as compared to nano. Vim is for advance and nano is for fresh user.

How to create and edit the file:

  1. Login to web server through SSH.
  2. Navigate the file which we want to create or edit it.
  3. Type vim as well as file name which we want to edit. E.g. our file name is test.html then we write like this:

[server]$ vim test.html

  1. When we open vim we confuse how to write file name here.

vim interface

  1. For enter in the insert mode of vim press I on keyboard.

                    vim insert mode

  1. If we want to delete a character which is under the cursor we can press ‘X’.
  2. If we have done changes with our file then we want to save our file then press ‘X’ as well as ensure that we are in insert mode.
  3. If we are not in insert mode and we want to save our file without any change then we can press q.
  4. If we have made some changes with our file and we want to save without any change and leave the file we can press q!. Butt ensure that we are not in insert mode.
  5. If we want to leave the vim then we can press esc

 Read the following articles:

70%OFF

Smart Sale

Hurry Up! Offer ends in
days 00 01 hrs 05 06 mins 40 41 secs 07 08
Buy Now
We are offering a Discount Promotion on All VPS. you can get upto 75% DiscountBuy Now
+ +