Are you looking through an extremely lengthy configuration file, one with hundreds of lines of comments, but only want to filter the important settings from it. In this article, we will show you different ways to view a configuration file without comments in Linux.
Read Also: ccat β Show βcat Commandβ Output with Syntax Highlighting or Colorizing
You can use the grep command to for this purpose. The following command will enable you view the current configurations for PHP 7.1 without any comments, it will remove lines starting with the ; character which is used for commenting.
Note that since ; is a special shell character, you need to use the \ escape character to change its meaning in the command.
$ grep ^[^\;] /etc/php/7.1/cli/php.ini
In most configuration files, the # character is used for commenting out a line, so you can use the following command.
$ grep ^[^#] /etc/postfix/main.cf
What if you have lines starting with some spaces or tabs other then # or ; character?. You can use the following command which should also remove empty spaces or lines in the output.
$ egrep -v "^$|^[[:space:]]*;" /etc/php/7.1/cli/php.ini OR $ egrep -v "^$|^[[:space:]]*#" /etc/postfix/main.cf
From the above example, the -v switch means show non-matching lines; instead of showing matched lines (it actually inverts the meaning of matching) and in the pattern β^$|^[[:space:]]*#β:
^$β enables for deleting empty spaces.^[[:space:]]*#or^[[:space:]]*;β enables matching of lines that starting with#or;or βsome spaces/tabs.|β the infix operator joins the two regular expressions.
Also learn more about grep command and its variations in these articles:
- Whatβs Difference Between Grep, Egrep and Fgrep in Linux?
- 11 Advanced Linux βGrepβ Commands on Character Classes and Bracket Expressions
Thatβs all for now! We would love to hear from you, share with us any alternative methods for viewing configuration files without comments, via the feedback form below.
If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.

Got Something to Say? Join the Discussion... Cancel reply