How to edit a file in Linux

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

You will learn all of that through our Blog.

Step-by-Step Guide to Using Nano for File Editing

introduction of nano editor:

  • The user interface of Nano looks like this. introduction 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

Scale Your Business with VPS: Instant Activation. Join Now!

Dedicated Resources, Affordable Price: Sign Up for VPS Hosting at $12.50/month with ARZ Host!

  • 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

General Instructions for Editing Files in Linux

  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.

Detailed Instructions for Editing Files with Vim

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

Creating and Modifying Files in Linux

  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. 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. 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

Limited-Time Deal! Secure up to 90% Off on Your Hosting Today!

Don’t Miss Out—Act Fast and Transform Your Hosting Experience at Unbeatable Prices!

For reliable and scalable hosting services, make sure to visit ARZ Host.

Table of Content