Unix/Linux 中的程序配置数据

发布于 2024-08-23 21:28:42 字数 177 浏览 5 评论 0原文

在 Unix/Linux 中保存用户配置数据的推荐方法是什么? 我的编程语言是C++。配置数据将以 XML/文本/二进制格式保存,我处理此类文件没有问题。我想知道我可以把它们保存在哪里。例如,在 Windows 操作系统中,配置数据可能保存在注册表中(旧方式)或用户应用程序数据目录中。那么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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

亢潮 2024-08-30 21:28:42

注册表的概念是Windows所特有的,微软曾经承认它的构思不周(参见这个这个 a>, 这个此(请参阅 #2)这个)。

在 Unix 和 Linux 中,系统范围程序的配置位于 /etc 中,或者可能位于特定于应用程序的子目录中。

每个用户的配置数据以文本格式保存在用户主目录中的隐藏文件中,或者保存在用户主目录中特定于应用程序的隐藏目录中。引用主目录的正确方法是通过环境变量HOME。通过将 . 作为名称的第一个字符来创建隐藏文件和目录。

系统范围配置的示例是 /etc/wgetrc/etc/ssh/。每个用户数据的示例有 $HOME/.bashrc$HOME/.mozilla/

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/.

夜还是长夜 2024-08-30 21:28:42

XDG 基本目录规范指定配置和其他文件应存储在 Linux 和其他基于 X 的操作系统中的位置:

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

这是现代方法,最终可能会减少典型用户主目录中的点文件混乱。

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.

月寒剑心 2024-08-30 21:28:42

点文件是经典的 Unix 解决方案。如果您想自己处理阅读/编写所有内容,那就去做吧。

然而,我使用的大多数现代程序都使用 GConf 来存储首选项。它使很多事情变得更容易,无论是作为开发人员还是作为用户(显然是作为管理员,但我没有这方面的经验)。

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).

放赐 2024-08-30 21:28:42

这在一定程度上取决于您对 Linux 的风格,但作为一般规则,大多数程序在 /etc 中的某个位置都有系统默认配置,并且主目录中的 .config 文件可以覆盖 /etc 目录中的默认设置。


很棒的一点 .config 应该是 .[配置文件的名称]

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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文