How To Edit File In Linux

Linux, an open-source operating system, is famous for its command-line interface (CLI). One needs to be comfortable with the command-line to manage a Linux system effectively. In this blog post, we’ll guide you through how to edit a file in Linux using various command-line editors.

1. Using Nano Editor

Nano is a user-friendly, simple, and customizable command-line text editor. Here’s how you can use Nano to open and edit a file in Linux:

nano filename

Replace ‘filename’ with your file’s actual name. After running this command, the file will open in the Nano editor. Here, you can edit your file. To save your changes and exit, press CTRL + X, then ‘Y’ to confirm, and finally, Enter.

2. Using Vi/Vim Editor

Vi/Vim is another widely-used text editor in Linux. It’s more powerful but also more complex than Nano. Here’s how to edit a file using Vi/Vim:

vi filename

Once again, replace ‘filename’ with your file’s actual name. Your file will open in Vi/Vim editor. To start editing, press i to enter insert mode. When you’ve finished editing, press Esc, then type :wq and press Enter to save your changes and exit.

3. Using Emacs Editor

Emacs is a highly extensible and customizable text editor. It’s more like an integrated development environment (IDE) than a simple text editor. To edit a file in Emacs:

emacs filename

Replace ‘filename’ with your actual file’s name. The file will open in Emacs editor. To save your changes and exit, press CTRL + X, then CTRL + S to save, and CTRL + X, then CTRL + C to exit.


Now, you know how to edit files in Linux using three different text editors. Feel free to choose the one you find the most comfortable to use. Remember, mastering the command-line interface is key to managing Linux effectively. Happy Linux-ing!