Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

86%
+11 −0
Q&A How to manage user-specific application data on Linux?

The traditional approach is to create either a single dotfile, or a single dot-directory, directly under the user's home directory, named for your application. Thus ~/.thromblemeisteradmin (which c...

posted 2y ago by Canina‭  ·  edited 2y ago by Canina‭

Answer
#2: Post edited by user avatar Canina‭ · 2022-08-13T09:28:52Z (over 2 years ago)
  • The traditional approach is to create either a single dotfile, or a single dot-directory, directly under the user's home directory, named for your application. Thus `~/.thromblemeisteradmin` (which could be a plain file or a directory containing any number of files). Sometimes a directory has a name suffix of `.d`, but that is redundant if there's only a directory. If it's a directory and appropriately named, it's generally assumed to be "owned" by the respective application, but entirely possibly under the control of the user.
  • However, while many applications still do this, **this practice is discouraged** on Linux since quite some time ago.
  • These days, the recommended location for such data, per the Linux [Filesystem Hierarchy Standard](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) version 3.0 ([authoritative standard document](https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html)) and the [XDG Base Directories specification version 0.8](https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html) is to, among others (the XDG base dirs specification has a more complete list and is the authoritative reference for the usage of each):
  • * store user-specific configuration data in an appropriately-named subdirectory of `$XDG_CONFIG_HOME`
  • * store relatively important user-specific data in an appropriately-named subdirectory of `$XDG_DATA_HOME`
  • * store relatively unimportant user-specific data, such as current application state or recovery files, in an appropriately-named subdirectory of `$XDG_STATE_HOME`
  • * store readily recreatable user-specific data, such as cache data, in an appropriately-named subdirectory of `$XDG_CACHE_HOME`
  • Each of these will very likely appear somewhere within a subdirectory of `/home`, but you can't necessarily count on that; consider `~root` which is often `/root` or [on some systems](https://en.wikipedia.org/wiki/Root_directory#Related_uses) `/var/root`.
  • If you really only need a single file for any of these, then substituting a file for the directory is generally acceptable; however, many applications still create a directory, if for no other reason then for future-proofing purposes. So it's not at all uncommon to see something like `$XDG_CONFIG_HOME/<someapplication>/config.ini`, with nothing else under that directory.
  • As an example, something like a hypothetical SSH client adhering to the XDG base dirs spec might store its configuration somewhere under `$XDG_CONFIG_HOME`, host and user keys somewhere under `$XDG_DATA_HOME`, and optimization data (I'm not sure exactly what that might be, but with the advent of post-quantum cryptography, who knows what might be useful?) somewhere under `$XDG_CACHE_HOME`.
  • The traditional approach is to create either a single dotfile, or a single dot-directory, directly under the user's home directory, named for your application. Thus `~/.thromblemeisteradmin` (which could be a plain file or a directory containing any number of files). Sometimes a directory has a name suffix of `.d`, but that is redundant if there's only a directory. Similarly, for historical reasons files have often had a `rc` suffix; thus `~/.procmailrc` for `procmail`. If it's a directory and appropriately named, it's generally assumed to be "owned" by the respective application, but entirely possibly under the control of the user.
  • However, while many applications still do this, **this practice is discouraged** on Linux since quite some time ago.
  • These days, the recommended location for such data, per the Linux [Filesystem Hierarchy Standard](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) version 3.0 ([authoritative standard document](https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html)) and the [XDG Base Directories specification version 0.8](https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html) is to, among others (the XDG base dirs specification has a more complete list and is the authoritative reference for the usage of each):
  • * store user-specific configuration data in an appropriately-named subdirectory of `$XDG_CONFIG_HOME`
  • * store relatively important user-specific data in an appropriately-named subdirectory of `$XDG_DATA_HOME`
  • * store relatively unimportant user-specific data, such as current application state or recovery files, in an appropriately-named subdirectory of `$XDG_STATE_HOME`
  • * store readily recreatable user-specific data, such as cache data, in an appropriately-named subdirectory of `$XDG_CACHE_HOME`
  • Each of these will very likely appear somewhere within a subdirectory of `/home`, but you can't necessarily count on that; consider `~root` which is often `/root` or [on some systems](https://en.wikipedia.org/wiki/Root_directory#Related_uses) `/var/root`. Do keep in mind that the `$XDG_*` environment variables might not be set; modern systems probably set them in their default configuration, but there's still the possibility that they are unset, in which case the specification provides fallback values for each.
  • If you really only need a single file for any of these, then substituting a file for the directory is generally acceptable; however, many applications still create a directory, if for no other reason then for future-proofing purposes. So it's not at all uncommon to see something like `$XDG_CONFIG_HOME/<someapplication>/config.ini`, with nothing else under that directory. The specification also calls out things like filesystem permissions and provides examples of how to handle failures. It's not that long; if you are considering doing this, **taking the few minutes to read through the actual XDG base directories specification is probably time well spent.**
  • As an example, something like a hypothetical SSH client adhering to the XDG base dirs spec might store its configuration somewhere under `$XDG_CONFIG_HOME`, host and user keys somewhere under `$XDG_DATA_HOME`, and optimization data (I'm not sure exactly what that might be, but with the advent of post-quantum cryptography, who knows what might be useful?) somewhere under `$XDG_CACHE_HOME`.
#1: Initial revision by user avatar Canina‭ · 2022-08-11T20:00:32Z (over 2 years ago)
The traditional approach is to create either a single dotfile, or a single dot-directory, directly under the user's home directory, named for your application. Thus `~/.thromblemeisteradmin` (which could be a plain file or a directory containing any number of files). Sometimes a directory has a name suffix of `.d`, but that is redundant if there's only a directory. If it's a directory and appropriately named, it's generally assumed to be "owned" by the respective application, but entirely possibly under the control of the user.

However, while many applications still do this, **this practice is discouraged** on Linux since quite some time ago.

These days, the recommended location for such data, per the Linux [Filesystem Hierarchy Standard](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) version 3.0 ([authoritative standard document](https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html)) and the [XDG Base Directories specification version 0.8](https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html) is to, among others (the XDG base dirs specification has a more complete list and is the authoritative reference for the usage of each):

 * store user-specific configuration data in an appropriately-named subdirectory of `$XDG_CONFIG_HOME`
 * store relatively important user-specific data in an appropriately-named subdirectory of `$XDG_DATA_HOME`
 * store relatively unimportant user-specific data, such as current application state or recovery files, in an appropriately-named subdirectory of `$XDG_STATE_HOME`
 * store readily recreatable user-specific data, such as cache data, in an appropriately-named subdirectory of `$XDG_CACHE_HOME`

Each of these will very likely appear somewhere within a subdirectory of `/home`, but you can't necessarily count on that; consider `~root` which is often `/root` or [on some systems](https://en.wikipedia.org/wiki/Root_directory#Related_uses) `/var/root`.

If you really only need a single file for any of these, then substituting a file for the directory is generally acceptable; however, many applications still create a directory, if for no other reason then for future-proofing purposes. So it's not at all uncommon to see something like `$XDG_CONFIG_HOME/<someapplication>/config.ini`, with nothing else under that directory.

As an example, something like a hypothetical SSH client adhering to the XDG base dirs spec might store its configuration somewhere under `$XDG_CONFIG_HOME`, host and user keys somewhere under `$XDG_DATA_HOME`, and optimization data (I'm not sure exactly what that might be, but with the advent of post-quantum cryptography, who knows what might be useful?) somewhere under `$XDG_CACHE_HOME`.