Read and Troubleshoot Linux Config Files 10x Faster! 2.0

This post is an iteration of my original post:

In it, I explained how reading and troubleshooting config files in Linux are sometimes a pain in the rear. In particular, when the config files are long and mostly comments.

When we are troubleshooting, we want to know just the effective settings that are going to be loaded at run time and nothing else. And read them quickly.

The script I provided in that original post works, but I’ve iterated it into a more elegant solution.

My solution – then and now – was inspired by a very useful book I discovered years ago: Perl One-Liners: 130 Programs That Get Things Done

So here is my new and improved version; I will also demo the heartburn it removes on two files: smb.conf and sshd_config:

perl -ne 'print unless /^(#|;|\n)/' <filename>

Notice how I defined a comment to be a “#” or a “;”.


Now, if we do a cat /etc/samba/smb.conf we can see how the output is extremely overwhelming with a lot of comments and blank lines:

cat /etc/samba/smb.conf

We could egrep -v "^(#|;)" /etc/samba/smb.conf to see the effective settings, but that will still leave ALOT of empty lines:

egrep -v “^(#|;)” /etc/samba/smb.conf

If we use the Perl Oneliner, we can remove ALL comments, and remove empty lines for EVEN BETTER readability

perl -ne ‘ print unless /^(#|;|\n)/ ‘ /etc/samba/smb.conf

Now we can quickly see our effective settings in /etc/samba/smb.conf.


We can run the same script on /etc/ssh/sshd_config for easier reading and troubleshooting:

perl -ne ‘ print unless /^(#|;|\n)/ ‘ /etc/ssh/sshd_config


Let take a step back and point out the main benefits with this script.

It will remove all comments (lines beginning with a “#” or “;”) and the empty lines. This will make reading the effective settings quicker and easier.

And make troubleshooting alot easier.

If this code helps you solve any problems, comment and let me know below

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: