Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When configuring samba, I use this method as suggested by the official docs.

testparm -s smb.conf.master > smb.conf

It means I can keep the fully commented version (smb.conf.master) but I also get a stripped down and easily parseable by humans and machine version in smb.conf

Is there an equivalent method for apache's config file?

share|improve this question

I do this frequently:

grep -v '^#' apache.conf > apache-stripped.conf

If you want to get really aggressive and remove blank lines as well:

egrep -v '^(#|$)' apache.conf > apache-stripped.conf

I should point out that the only reason to do this is to make it easier for you to read if you find the comments distracting. Apache, of course, doesn't mind. There is no performance gained by removing the comments from the live Apache config, aside from maybe a few microseconds saved at startup.

share|improve this answer
Thanks, As I just mentioned in a comment to theothereceive, it really is for human scanning and not for performance reasons. So the first one would probably be what I am looking for. But would it be possible to modify it so that real comments are kept but commented out options removed? Maybe by removing lines beginning with a single # but not ##? – blndcat Jul 18 '09 at 2:17
Instead of stripping out all empty lines (which makes it almost as unreadable), I just run uniq on it which limits it to one blank line between other lines. – Matt Simmons Jul 18 '09 at 3:42
blndcat asked this question NOT only because his 'Samba trick' removes comments. He asked because it also removes all config settings which are compiled-in as default settings in his current smbd. His command strips down his smb.conf to a bare minimum. As such it can give a huge performance benefit, because every client connections spawns a new smbd process, and each smbd process re-reads the smb.conf config file every 30 seconds. And Samba is known for its ability to serve 1000s of concurrent client connections in some environments... – Kurt Pfeifle Aug 2 '10 at 10:45

You can test the configuration file with apachectl configtest (usually called apache2ctl on debian systems). That's the closest equivalent I can think of.

It wouldn't be too much trouble to write a script that would combine configtest with something else (grep, awk, sed etc.) to duplicate what you're doing with testparm.

Personally, I'd find a httpd.conf with no comments at harder to read than one that has a few comments, is there any specific reason you're trying to do this?

share|improve this answer
It isn't the real comments that are the problem, it is the commented out options. They really clutter up the config file leading to it being hard to scan though, especially when troubleshooting. But if I removed the commented out options, it is more work to enable them in the future or use them for reference. – blndcat Jul 18 '09 at 2:11

this is really a comment on Insyte's answer, but i can't format it readably as a comment. plus this is too long for a comment :)

sed -e 's/^[[:space:]]\+\(#\|\$\)/#/'  apache.conf | grep -v '^#' | uniq

using sed like this will strip out whitespace before full-line comments and before all end-of-line markers. piping through uniq will strip all but the first empty line of any sequence of consecutive empty lines (i.e. leaving one blank line between 'paragraphs'). IMO, that makes it more readable.

using uniq here does have the small risk that any other consecutive duplicate lines will be deleted, but that's not likely to be a problem in practice.

also, to answer your question about stripping single-# comments, but not double ## comments...first i'll mention that double and triple # comments are common in config files anyway so you probably want to use something else. '#:', for example. then use something like:

sed -e 's/^[[:space:]]\+\(#\|\$\)/#/'  apache.conf | egrep -v '^#[^:]|#$' | uniq
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.