| by Arround The Web | No comments

How to Edit File in Linux

If you’re new to the Linux operating system and want to learn some basic points, you’re in the right place. This tutorial is mentioning one of the general beginnings points you should know about.

How to edit a file while using the Linux system is the question that arrives in every beginner’s mind. When executing programs on a system, sometimes we need to modify them in a timely manner. You can perform such tasks through two of the most used editors’ i-e, nano editor, and vim editor.

Let’s check how they work:

How To Edit File in Linux Through Nano Editor

Nano editor is a straightforward built-in editor in Linux distributions used to edit files. We don’t need to learn much before using this, it’s simple. All the basic operations with the symbols are mentioned at the bottom of the editor. You can make use of them with the “Control (ctrl)” key. There is no pre-requisite of it or no command to operate this.

To open nano editor, first check its version using command in terminal:

$ nano --version

(If it is not installed in your system; type the following command to get it “$ sudo apt install nano”)

Simple type “nano” with the file name that needs to be edited in the editor. For example, there is a file in my system name “testing.txt”, to open it, type:

$ nano testing.txt

To edit it, move the cursor where you want to add required text and start typing.

After modification press “ctrl+o” keys to save it:

File modification has been saved successfully. Now, press “ctrl+x” keys to exit the nano editor.

To verify the modification, open the terminal and run cat command with the file name:

$ cat testing.txt

How To Edit File in Linux Through Vim Editor

The vim or vi editor is most likely a built-in Linux editor that comes up with multiple modes. Most of the tools contain one mode to edit documents. But when you start working with vim editor, you will get several things like insert, command, line mode and many more.

Before getting started with vim editor, you should know some basic symbols to switch mode:

  • “i” for insert mode
  • “w” to save file
  • “Esc” for normal mode
  • “:q” to quit editor without saving
  • “:wq” to save updated document and quit editor

To check which version is installed in your system, type in terminal:

$ vi --version

Now, type vim with the file name to open it, for example to open “test.txt” file, type:

$ vim test.txt

If there is no “test.txt” file in the system backup, then this command will create a new file of this name.

Edit File: Now to edit the file, press “i”, it will activate insert mode and allow you to add anything in the file.

Save File: Use the following “:wq” operation to save an updated file and quit the vi editor.

Conclusion

Editing a file or document is the most common thing while using any system. Similarly, in the Linux operating system, you might need editing all the time. Linux distributions come with the multiple built-in editing tools i-e, vim, and nano. This article has briefly explained how to edit files using vim editor and nano editor.

Share Button

Source: linuxhint.com

Leave a Reply