How-To Geek

How to Comment Out and Uncomment Lines in a Configuration File


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 #.


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.


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.

Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

  • Published 07/8/12

Comments (10)

  1. Darryl Drury

    REM You may have missed a few.
    // Thinking about it, I’m sure you have.
    :: From memory I can’t think of any.
    — OK never mind. Sorry.

  2. rws8258

    echo @DD
    echo Good one.

  3. Mike Brazil

    A widely inclusive list of comment formats would have been a nice addition to this article.

  4. Mike Brazil

    Something like this:

    C Fortran 77 and earlier; the ‘C’ must be in column 1 of a line to indicate a comment.
    REM, ::, : BASIC, COMMAND.COM, cmd.exe
    NB. J; from the (historically) common abbreviation Nota bene, the Latin for “note well”.
    ⍝ APL; the mnemonic is the glyph (jot overstruck with shoe-down) resembles a desk lamp, and hence “illuminates” the foregoing.
    # bash, Cobra, Perl, Python, Ruby, Windows PowerShell, PHP, Maple
    % TeX, Prolog, MATLAB,[7] Erlang, S-Lang, Visual Prolog
    // ActionScript, C (C99), C++, C#, D, Go, Java, JavaScript, Object Pascal (Delphi), Objective-C, PHP, Scala
    ‘ Visual Basic, VBScript, RealBasic
    ! Fortran, Basic Plus, Inform
    ; AutoHotkey, AutoIt, Lisp, Common Lisp, Clojure, Rebol, Scheme, many assemblers
    — Euphoria, Haskell, SQL, Ada, AppleScript, Eiffel, Lua, VHDL, SGML
    * COBOL, PAW, many assemblers
    || Curl
    ” Vimscript
    \ Forth
    :: Batch file

  5. trigger

    /** for a quick shortcut to javadoc template in Eclipse

  6. spike

    HTML comment

    I’m not sure anyone has mentioned this one yet

  7. spike

    Oops you’ll have to look at the page source code to see that one :)

  8. HWND

    I’m surprised that no one has yet mentioned that in RPG (that’s Report Program Generator, not Role-Playing Games) comments are indicated by an asterisk (*) in column 7.

  9. Citrus Rain


    That would be…

    <!-- Something like this. -->

  10. spike

    @Citrus Rain: Yeah I put it in, I just didn’t realize it was filtering html tags

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!