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:
- The user interface of nano looks like this. introduction of nano editor
- On the top of the nano editor it tells about the version of nano and the file name.
- 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.
- Below of the editing area here are some shortcut keys.
How to edit file:
- Login to your web server through SSH.
- Navigate the directory location where you want to edit or create the file.
- 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.h
- A file is open name is test.html.
- Now you can type your data which you want.
- When you have done to write your data then you can save your file by press ctrl+o.
- On the bottom of the prompt he asking you to write the file name. you confirm your file name test.html.
- Press the enter key for to save the file.
- 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:
- Login to web server through SSH.
- Navigate the file which we want to create or edit it.
- 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
- When we open vim we confuse how to write file name here.
- For enter in the insert mode of vim press I on keyboard.
- We want to delete a character which is under the cursor we can press ‘X’.
- 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.
- We are not in insert mode and we want to save our file without any change then we can press q.
- 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.
- If we want to leave the vim then we can press esc