Quick Links

You may have seen instructions that tell you to “uncomment” or “comment out” lines in a configuration or source code file. This is a simple process, but may not be self-explanatory to people that don’t understand the file’s structure.

The interpreter ignores lines marked as comments, which are only to aid humans in understanding the file. Because of this, comments can be used to disable or enable configuration options in configuration files.

The Short Answer

You can “uncomment a line” in a configuration file by removing the # at the start of the line. Or, to “comment out” a line, add a # character to the start of the line. (Note that some languages have different comment formats, so this may not be true if you’re working with a source code file.)

For example, let’s say you have a file with the following text:

# To enable feature X, uncomment the line below

#FeatureX = Enabled

To uncomment the line, you’d remove the # character before it such that the text became:

# To enable feature X, uncomment the line below

FeatureX = Enabled

To comment out a line, you’d follow this process in reverse. For example, this text:

# Comment out the line below to disable feature Y

FeatureY = Enabled

Would become:

# Comment out the line below to disable feature Y

#FeatureY = Enabled

Save the configuration file after making these changes.

What is a Comment?

To understand what exactly this means and why we’re referring to “uncommenting” or “commenting out” lines rather than “enabling” or “disabling” them, it’s important to understand the structure of a configuration file. In addition to actual configuration directives, these files can contain comments. These comments aren’t for the computer – they exist to explain the format of the configuration file to anyone reading it. The # before each line tells the computer that this is a comment line – the computer should ignore it, skip over it, and try to interpret the next line that doesn’t begin with a #.

image

In some cases, a configuration file may include a configuration option that’s disabled by default. To disable the configuration instruction, a # is included before its line as well, instructing the computer to ignore the line. To enable one of these configuration instructions, all you have to do is remove the # character. To disable any configuration instruction – or add your own comments – just include a # at the start of each line.

image

Other Comment Formats

While this is the format commonly used in configuration files and shell scripts – most notably on Linux and other UNIX-like operating systems – other languages may use other comment formats.

For example, if you’re working with a PHP script, you might see a section like the one below:

/* This section is commented out by default to avoid causing problems

to enable feature X, uncomment the section below

line of php code

another line of php code */

To uncomment the section and enable the feature, you’d change this section to:

/* This section is commented out by default to avoid causing problems

to enable feature X, uncomment the section below */

line of php code

another line of php code

This is a multi-line PHP comment (C-style comment) where /* begins the comment and */ ends the comment.