Is there a guideline for Unix config files [closed]
Asked Answered
O

1

15

Most config files are ini files (format: name=value\n). Is there any documentation or an article/guideline on this matter.

Or is anyone supposed to keep close to this format on good will?

Omarr answered 18/4, 2011 at 11:38 Comment(2)
There are a lot of libraries (or existing functions) that you can reuse to read and parse those files. But feel free to invent your own format or use XML...Klemperer
From FreeBSD Handbook: freebsd.org/doc/handbook/kernelconfig-config.html And Linux Kernel: kernel.org/pub/linux/libs/pam/Linux-PAM-html/…Omarr
C
18

Unfortunately, UNIX is hardly decided on this issue. There are too many formats. With session managers like Gnome, some apps have moved out from maintaining config files to keeping stuff in the Gnome registry (gconf).

Here are some general observations.

The ini format you alluded to is fairly widespread. It does have the problem that you'd have to do some tricks to assign a list of values etc. but for most situations, it's fine, well supported and widely available.

Most formats used in UNIX rely on the # character as commenting the rest of the line. If you are rolling out something by yourself, it would be good to stick to this.

YAML is a human readable lightweight format that you can use (and many apps do use it though not as much as I'd like).

There's a convention that all system level config files are kept in /etc and user level ones are kept as file starting with . in the users home directory (dot files).

Some applications (notably Emacs) keeps a runnable program in a full fledged programming language as it's config file. This might be unsafe in an untrusted environment but very powerful and useful in a trusted one.

For a new project, I'd go with ini as a .programrc in the home directory.

There's a useful section in the art of unix programming about configuration formats and files that might be worth your while to check out.

Chauvinism answered 18/4, 2011 at 11:55 Comment(3)
A good starting point/litmus test would be to see the formats that already have a lens in augeas.netAblepsia
With Eric S. Raymond's articles on rc files linked below in mind I guess there is nothing more to say. Thanks.Omarr
Also, please consider following the current trend of having the per-user config file(s) under ~/.config/appname rather than directly under the user home dir, helping reduce home dir clutter. E.g. on my home dir @work, I seem to have 242 dotfiles/dirs.. :(Kirsten

© 2022 - 2024 — McMap. All rights reserved.