HowTo: View a Config File Without Comments

With the help of grep command it is quite easy just to look at the active setting of configuration files, omitting comments.

The following command will display the content of the file somefile.conf, omitting blank lines and the lines started with #:

$ grep -v '^\s*$\|^\s*\#' somefile.conf

Also, you can pipe the output to a new file:

$ grep -v '^\s*$\|^\s*\#' somefile.conf > newfile.conf

To make filtering easier, you can add an alias for ‘clean config’:

$ alias cf='grep -v '^\s*$\|^\s*\#'

And use it as follows:

$ cf /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict -6::1
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
Was it useful? Share this post with the world!

Leave a Reply