You may have heard the term "commenting out," in relation to Linux configuration files. What does that mean?

Here's everything you need to know about comments in configuration files and how to comment and uncomment lines on Linux.

What Does "Commenting Out" Lines Mean on Linux?

Linux relies on plain text configuration files to manage system settings. Many of them are supplied and already filled out by distribution or upstream developers. Others may be added after you install a new program.

You may come across instructions that tell you to "comment out" a line. This means adding a comment character, typically a "#", also known as the Hash or Pound character, to the beginning of the line, so that it's read as a comment rather than a piece of code. This means that everything in the line that comes after the comment character will be ignored.

Why Comment Out Lines?

This is typically done to disable an option in such a way that you can re-enable it later. It's like covering things you don't want to get paint on with painter's tape when painting a room, then removing it after the project's done.

Configuration files in Linux have different styles but this convention is common.

How to Comment Out Lines in a Text Editor

Commented out line in text editor

Commenting out lines is simple. You just open a file you want to edit in a text editor and add the comment character at the beginning of the line you want to disable.

Because many system files are owned by root, you'll have to use sudo to open them. For example, to use Vim to edit a file as root:

        sudo vim /etc/example.conf
    

Many text editors use syntax highlighting. This means you'll have a visual cue that you've commented out the line when it changes color. Save the file after you've made the changes you want.

How to Re-enable Commented Out Lines

Perhaps some change isn't working for you. Going back to changes you've made is also easy. Just delete the comment character (#) in the line you edited. Then save the file and you will be back to where you were before. Depending on what file you edited, you may have to restart the system for any changes to take effect.

It's also a good idea when working on system files to save backup copies. You can just replace them if something goes wrong. You might even consider backing them up to a separate drive in case your system becomes unbootable.

Now You Can Comment and Un-Comment Lines in Linux

It's easy to comment out and re-enable lines in Linux to edit configuration files non-destructively. All you need to do is open your favorite text editor and add and remove a "#" character.

These configuration files are spread across many directories in the filesystem. The Linux filesystem hierarchy can seem overwhelming at first, but once you know the lay of the land, you can find the file you want effortlessly.