Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to View Configuration Files Without Comments in Linux  (Read 1151 times)

0 Members and 1 Guest are viewing this topic.

sibij

  • Guest
How to View Configuration Files Without Comments in Linux
« on: April 21, 2018, 10:38:44 pm »
How to View Configuration Files Without Comments in Linux

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.

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.

Code: [Select]
grep ^[^\;] /etc/php/7.1/cli/php.ini


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.
Code: [Select]
$ 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.

Code: [Select]
$ egrep -v "^$|^[[:space:]]*;" /etc/php/7.1/cli/php.ini
OR
$ egrep -v "^$|^[[:space:]]*#" /etc/postfix/main.cf


    ^$ – 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.