Archive

Archive for September, 2009

A quick(er) way to view config files

September 5, 2009 Leave a comment

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.

Categories: Bash, linux, Tip