Linux / UNIX View Only Configuration File Directives ( Uncommented Lines of a Config File )

Linux / UNIX View Only Configuration File Directives ( Uncommented Lines of a Config File )

To view only the configuration file directives (uncommented lines) of a config file on Linux or UNIX, you can use the grep command with the -v option to invert the match and exclude commented lines.

For example, to view the uncommented lines of the /etc/nginx/nginx.conf file, you can use the following command:

grep -v '^#' /etc/nginx/nginx.conf
Source‮‬:www.lautturi.com

This will print the uncommented lines of the nginx.conf file to the console.

You can also use the -E option to enable extended regular expressions and match lines that start with # or ; as commented lines:

grep -vE '^#|^;' /etc/nginx/nginx.conf

To save the output to a new file, you can use the > redirection operator:

grep -v '^#' /etc/nginx/nginx.conf > uncommented.conf

This will create a new file named uncommented.conf with the uncommented lines of the nginx.conf file.

Keep in mind that these are just a few examples of how to view the uncommented lines of a config file on Linux or UNIX. You can customize the regular expression and the input and output files to meet the specific requirements of your system. You should also regularly review and update the config file to ensure that it is effective and efficient.

Created Time:2017-10-29 22:08:55  Author:lautturi