开发者

Program configuration data in Unix/Linux

What is recommended way to keep a user configuration data in Unix/Linux? My programming language is C++. Configuration data will be kept 开发者_运维知识库in XML/text/binary format, I have no problem with handling such files. I want to know where can I keep them. For example, in the Windows OS configuration data may be kept in the Registry (old way) or in user application data directory. What about Linux? I need read/write access to configuration files.


The concept of the registry is peculiar to Windows, and Microsoft once admitted to it being ill-conceived (see this, this, this, this (see #2), and this).

In Unix and Linux, configuration for system-wide programs is in /etc or maybe an application-specific subdirectory.

Per user configuration data are kept in the user's home directory in a hidden file—in text format—or an application-specific hidden directory in the user's home directory. The proper way to reference the home directory is through the environment variable HOME. Hidden files and directories are created by making . the first character of the name.

Examples for system-wide configuration is /etc/wgetrc and /etc/ssh/. Examples of per-user data are $HOME/.bashrc and $HOME/.mozilla/.


The XDG Base Directory Specification specifies where configuration and other files should be stored in Linux and other X-based operating systems:

http://freedesktop.org/wiki/Specifications/basedir-spec

This is the modern way, and may eventually reduce the dotfile mess in the typical user's home directory.


Dotfiles are the classic Unix solution. If you want to deal with reading/writing everything yourself, go for it.

However, most modern programs I use have used GConf for storing preferences. It makes a lot of things easier, both as a developer and as a user (and apparently as an administrator, but I have no experience there).


That depends a little on your flavor of Linux but as a general rule most programs have the system default configuration somewhere in /etc with .config files in your home directory that can override the defaults in the /etc dir.


Great point .config should be .[Name of config file]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜