Linux config without comments

How to View a Configuration File Without the Comments

This guide will give you a couple of options/suggestions on how to view a config file in Linux without the comments.

I have to often make changes to configuration files such as httpd.conf and squid.conf. These files have a large number of lines that are commented out, mostly comments and some possible configuration directives that have been commented out as they are not required by default. A problem I face while editing such files is that there are so many lines commented out that I need to scroll down many lines before I can find the next active configuration directive. I found a fine solution to help me out with this.

I now use the following command when I want to just look at the active directives in the Apache configuration file:

This command (sed) reads the file /etc/httpd/conf/httpd.conf and filters out all the comments and extra white spaces, leaving just the active configuration settings. This makes it very easy for me to look at the configuration file.

If you want to just filter out the lines that begin with comments run the following command:

It’s pretty much the same command as earlier with a small change. The first * is replaced by ^, which is regex for beginning of line.

Update: see several of of the helpful comments below if these commands don’t allow you to properly view a config file without the comments.

Источник

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. In this article, we will show you different ways to view a configuration file without comments in Linux.

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.

Читайте также:  Linux mint нет bluetooth

Note that since ; is a special shell character, you need to use the \ escape character to change its meaning in the command.

View Files Without Comments

View Files Without Comments

In most configuration files, the # character is used for commenting out a line, so you can use the following command.

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

View Files Without Spaces

View Files Without Spaces

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:

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.

Источник

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. In this article, we will show you different ways to view a configuration file without comments in Linux.

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.

Читайте также:  Linux get my dns server

View Files Without Comments

In most configuration files, the # character is used for commenting out a line, so you can use the following command.

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

View Files Without Spaces

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:

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.

Источник

Cat a File, Without the Comments

I recently had to install a couple of squid servers to act as reverse proxies for a webcluster. You can teach the squid server to stand in between in the end users and the webservers, and to store all the static content ( .jpg .flv .css .htm for example ) in the RAM. This saves a lot of I/O and bandwidth on the webservers, and it can really speeds up a site. And the end of the road the webservers’ load dropped with 92%. But before all this worked, I had to run through a massive config file and since the squid config file is their manual at the same time, it’s about 5000 lines long. So I had to find out a way to filter only the important settings from the config file.

This is what I came up with:

$ cat /etc/squid/squid.conf | egrep -v "(^#.*|^$)" 

Explained

egrep -v means leave the following out ^#.* means patterns that begin with a # | means or ^$ means patterns that are empty 

Updates

update #1

Thanks to an insightfull comment by Darwin Award Winner on this article, here’s a version that would also filter comments with spaces before the #, such as comments that are indented with code blocks:

$ cat /etc/squid/squid.conf | egrep -v "^\s*(#|$)" 

Источник

Читайте также:  Microsoft azure and linux

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. In this article, we will show you different ways to view a configuration file without comments in Linux.

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.

How to View Configuration Files Without Comments in Linux

In most configuration files, the # character is used for commenting out a line, so you can use the following command.

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

How to View Configuration Files Without Comments in Linux

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:

  1. What’s Difference Between Grep, Egrep and Fgrep in Linux?
  2. 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.

Источник

Оцените статью
Adblock
detector