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.
在Unix/Linux中保存用户配置数据的推荐方法是什么?我的编程语言是c++。配置数据将以XML/text/二进制格式保存,我对处理此类文件没有问题。我想知道我在哪里可以保存它们。例如,在Windows OS中,配置数据可以保存在注册中心(旧方式)或用户应用程序数据目录中。Linux呢?我需要对配置文件进行读/写访问。
4 个解决方案
#1
9
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).
注册表的概念是Windows特有的,微软曾经承认它考虑不周(看这个、这个、这个、这个(见#2)和这个)。
In Unix and Linux, configuration for system-wide programs is in /etc or maybe an application-specific subdirectory.
在Unix和Linux中,系统范围程序的配置位于/etc或可能是特定于应用程序的子目录。
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.
每个用户配置数据都保存在用户的主目录中的一个隐藏文件中—文本格式—或用户的主目录中的一个特定于应用程序的隐藏目录。引用主目录的正确方法是通过环境变量home。隐藏文件和目录是创建。名字的第一个字符。
Examples for system-wide configuration is /etc/wgetrc
and /etc/ssh/
. Examples of per-user data are $HOME/.bashrc
and $HOME/.mozilla/
.
系统范围配置的示例是/etc/wgetrc和/etc/ssh/。每个用户数据的例子是$HOME/。bashrc。mozilla /和$ HOME /(。
#2
4
The XDG Base Directory Specification specifies where configuration and other files should be stored in Linux and other X-based operating systems:
XDG基本目录规范指定了配置和其他文件应该存储在Linux和其他基于x的操作系统中的位置:
http://freedesktop.org/wiki/Specifications/basedir-spec
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.
这是一种现代的方式,可能最终会减少典型用户主目录中的dotfile混乱。
#3
2
Dotfiles are the classic Unix solution. If you want to deal with reading/writing everything yourself, go for it.
Dotfiles是经典的Unix解决方案。如果你想自己处理阅读/写作,那就去做吧。
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).
然而,我使用的大多数现代程序都使用GConf来存储首选项。它使很多事情变得简单,无论是作为开发人员还是作为用户(显然作为管理员,但我在那里没有经验)。
#4
1
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.
这在一定程度上取决于您的Linux风格,但作为一个通用规则,大多数程序在您的主目录中都有一个系统默认配置,可以覆盖/etc目录中的默认值。
Great point .config should be .[Name of config file]
配置的要点应该是。
#1
9
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).
注册表的概念是Windows特有的,微软曾经承认它考虑不周(看这个、这个、这个、这个(见#2)和这个)。
In Unix and Linux, configuration for system-wide programs is in /etc or maybe an application-specific subdirectory.
在Unix和Linux中,系统范围程序的配置位于/etc或可能是特定于应用程序的子目录。
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.
每个用户配置数据都保存在用户的主目录中的一个隐藏文件中—文本格式—或用户的主目录中的一个特定于应用程序的隐藏目录。引用主目录的正确方法是通过环境变量home。隐藏文件和目录是创建。名字的第一个字符。
Examples for system-wide configuration is /etc/wgetrc
and /etc/ssh/
. Examples of per-user data are $HOME/.bashrc
and $HOME/.mozilla/
.
系统范围配置的示例是/etc/wgetrc和/etc/ssh/。每个用户数据的例子是$HOME/。bashrc。mozilla /和$ HOME /(。
#2
4
The XDG Base Directory Specification specifies where configuration and other files should be stored in Linux and other X-based operating systems:
XDG基本目录规范指定了配置和其他文件应该存储在Linux和其他基于x的操作系统中的位置:
http://freedesktop.org/wiki/Specifications/basedir-spec
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.
这是一种现代的方式,可能最终会减少典型用户主目录中的dotfile混乱。
#3
2
Dotfiles are the classic Unix solution. If you want to deal with reading/writing everything yourself, go for it.
Dotfiles是经典的Unix解决方案。如果你想自己处理阅读/写作,那就去做吧。
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).
然而,我使用的大多数现代程序都使用GConf来存储首选项。它使很多事情变得简单,无论是作为开发人员还是作为用户(显然作为管理员,但我在那里没有经验)。
#4
1
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.
这在一定程度上取决于您的Linux风格,但作为一个通用规则,大多数程序在您的主目录中都有一个系统默认配置,可以覆盖/etc目录中的默认值。
Great point .config should be .[Name of config file]
配置的要点应该是。