How to comment out lines in configuration files on Linux

This tutorial focuses on commenting lines in a configuration file on Linux, the examples used here are from Debian 10. However they will work on any other linux distribution too. Lines get commented out do deactivate them. You can use this also to add comments to your config files to describe what you changed for later use.

Whenever you want to comment a line, put a # in an appropriate place in a file. Anything beginning after # and ending at the end of the line won’t get executed.

Following are some examples,

# This is a comment line

This comments out the complete line.

This is a #comment line

This comments out only the last part of the line starting at #.

Commenting in Linux config file

While # is the most common char to comment out lines, there are some files which use a different syntax. For example the php.ini file:

Comment out line in php.ini

Lines in php.ini get commented out by using the ; char.