How To Edit Files In Linux?

Linux provides different ways and tools in order to edit files. These methods can be called command-line editors and GUI editors. As a text-based operating system and most of the configuration is stored as a text file the configuration changes generally require editing files.

Why Edit Files In Linux?

As stated Linux is a command-line and text-based operating system the files can be edited for different reasons.

  • Change a text file
  • Change network and system configuration
  • Add and remove data into a text-based database
  • Change apache web server configuration
  • Open log files

Linux File Editing Tools

Linux is a free and open-source operating system that provides a lot of different file or text editors in order to edit files. Some of the are command lines that can be worked over an SSH connection, and console, and some of them are GUI-based which requires a desktop environment.

vicommand line
vimcommand line

Edit Files with Vim/Vi

Vim or Vi is one of the most popular command-line text editors which can be used to edit files in Linux. Vim is the next generation of the vi file editor which is managed with commands and keys. In order to edit a file with Vim/Vi, we should open the file from the command line.

$ vim /home/ismail/file.txt

Now we should change into the edit mode with the i key like below. But before we will sure the command mode is enabled.


Now we can edit our file. After the edit is completed we will save the changes with the ESC and then :w keys.

:wqSave and Quit
:!qQuit without Saving
iInsert Mode
ESCCommand Mode

Edit Files with Nano

Nano is a command-line text editor too but it is more traditional than vim. Nano uses keys in order to edit and save a file. We will open the file with the nano command like below.

$ nano /home/ismail/
Edit Files with Nano

Move the cursor to the position you want to change and make changes. After you have completed your change press CTRL+x in order to exit by saving changes.

Keyboard ShortcutDescription
CTRL+OWrite Out
CTRL+RRead File

Leave a Comment