Home > Bash, linux, Tip > A quick(er) way to view config files

A quick(er) way to view config files

Quite often we need to check the (effective) settings in a configuration file and the most common way is to use grep

grep -v ^# config_file

But this does not work well because
1) it does not filter out empty lines
2) it does not filter out lines start with space(s) or tab(s) and are followed by # or ; (openvpn uses both # and ; as comment characters)

As a solution to the solve the above limitations, I use the following egrep command quite often

egrep -v "^[[:cntrl:] ]*[#;]|^[[:cntrl:] ]*$ config_file

But the above command is a lot of typing therefore I add the following alias to my ~/.bashrc and it filters out all comment lines and empty lines [ including lines containing only space(s) and/or tab(s) ] nicely.

alias cf='egrep -v "^[[:cntrl:] ]*[#;]|^[[:cntrl:] ]*$"'

With this alias I just need to type the following to view my config files:

cf config_file

Reference:
Inspired by http://www.linuxjournal.com/content/tech-tip-view-config-files-without-comments, I also left a comment there (rc3) but that’s not the final version that I am using here.

Advertisements
Categories: Bash, linux, Tip
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: