Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

VITUX Home Linux CentOS Debian Ubuntu Shell

Linux Compendium

How to Edit Config Files in Ubuntu

Configuration files contain the information required to control the operation of a program. Linux users,
especially Linux administrators, must know how to edit configuration files to maintain an Ubuntu server or
desktop. Configuration files on Ubuntu are stored in subdirectories of the /etc folder as a text file and can be
edited using text editors. Some of the examples of config files are host.conf, hosts. resolv.conf, networks,
syslog.conf etc. in Linux-based operating systems.

To make any configuration changes, you have to open and edit the file using a text editor. In this article, I will
describe multiple ways to edit config files in Ubuntu. The steps described in this guide have been tested on
Ubuntu 20.04, but they will work on other Ubuntu versions too.

Using Gedit Editor


Using Nano Editor
Using Vim Editor
Using Gvim Editor
Using Emacs Editor

Now let’s take a look at these text editors. By using these editors, you can easily edit files in terminal.

Using Gedit Editor


Gedit is the default text editor of the Gnome desktop environment. It supports tabs so you can open
different files in multiple tabs. It is the simpler and easier text editor as compared to other available text
editors.
To edit a config file in text editor, launch Terminal by pressing Ctrl+Alt+T key combinations. Then type the
below command as sudo:

$ sudo gedit /path/to/filename

Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When
prompted for a password, enter sudo password.

Example: editing of the /etc/resolv.conf file

Search

Search

It is like the notepad editor in Windows OS. As soon as the editor window opens, you can start typing or
editing without entering in any mode. Once you have done with the editing, press Ctrl+S to save the file. About This Site
Vitux.com aims to become a Linux compendium with lots of
unique and up to date tutorials.

Using Nano Editor


Nano is the simplest and the powerful built-in editor in the many Linux distributions. You do not have to
learn the Nano editor before using it and also there is no need to remember the commands. They are
displayed at the bottom and can be triggered with the Ctrl key. For instance to save a file, press Ctrl+O.

To edit any config file, simply open the Terminal window by pressing the Ctrl+Alt+T key combinations.
Navigate to the directory where the file is placed. Then type nano followed by the filename that you want to
edit.

$ sudo nano /path/to/filename

Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When
prompted for a password, enter sudo password.

Now you can edit and make changes in the config file using Nano editor.
Once you have done editing, press Ctrl+O to save and Ctrl+X to exit the Editor. Latest Tutorials
Using Vim Editor How to Disable/Enable Automatic Screen Lock in Linux Mint
20 trough CLI
Vim or Vi editor also comes pre-installed with most Linux distributions. It has no visible prompts or control
that can be a little harder for beginners. However, once you learned it, it is the more quick and powerful tool 4 Ways to Show all Drives (Mounted and Unmounted) on
for editing. Using Vim, you can edit and view multiple files in one session. Linux

To open a file in Vim editor, open the Terminal window by pressing the Ctrl+Alt+T key combinations. Then Linux tee command explained (with examples)
type vi as sudo followed by filename along with the file path like: 13 Important Privacy and Security Settings in Ubuntu Linux

Install and Use Psensor in Ubuntu 20.04


$ sudo vi /path/to/filename

report this ad
Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When
prompted for a password, enter sudo password.
Then edit the file using Vim editor. Note that when the editor opens, you enter command mode. Here are the
few steps to edit a file in Vim editor:

To edit the file, Press I from keyboard to enter into insert mode, here you can do editing just like the
normal editor.
When done with editing, get out of this mode by pressing Esc. It will return you to normal mode.
To save the file, type :w in command mode
To quit the editor, type :q in command mode
To combine the above actions type :wq to save and quit simultaneously.

Using Gvim Editor


Gvim is a Vim editor with a graphical user interface. To install Gvim, launch Terminal by pressing Ctrl+Alt+T.
then type the below command in Terminal to start the installation.

$ sudo apt-get install vim-gnome


Once done with the installation, you can open and edit any config file in it. Type the below command with
sudo in Terminal to open any config file in Gvim:

$ sudo gvim /path/to/filename

Press I to enter in insert mode where you can edit the file.
In Gvim editor, you can do various functions using the toolbar just like any normal GUI application like saving
the file, undo, redo, finding a keyword, etc.

Using Emacs Editor


Emacs is also a text editor but it is not a built-in editor. You have to manually install it using the Ubuntu
Terminal. It has so many features including a built-in web browser, calculator, calendar, Terminal, etc.

To install Emacs editor, launch Terminal by pressing Ctrl+Alt+T key combinations. Type the below command
in Terminal as sudo:

$ apt-get install emacs

Once done with the installation, you can open and edit any config file in it.

To open a config file using emacs editor, type emacs followed by filename along with the file path in the
below syntax:

$ sudo emacs /path/to/filename

Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When
prompted for a password, enter sudo password.
Edit the file as normal and save it using the toolbar.

You can also open the config file in bash instead of a separate window.

Type the following command as sudo in Terminal:

You might also like