Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of ini/config files in linux/unix?

Two questions, really:

  1. Is there a standard/convention regarding the placement on configuration files?

    For system or quasi-system programs they seem to usually be somewhere in /etc. It seems less clear for plain application programs or programs with insufficient privileges for /etc.

  2. In processing program options is there a standard hierarchy of what takes precedence? E.g. does a command line option override an initialization file and/or an environment variable? Vice versa? Or is this entirely up to the developer?

like image 905
Newton Falls Avatar asked Jun 21 '09 15:06

Newton Falls


People also ask

Where is config ini in Linux?

The vast majority of Linux config files can be found in the /etc/ directory or a sub-directory. Most of the time these configuration files will be edited through the command line, so get comfortable with applications like Nano or Vi.

Where are config files in UNIX?

Unix configuration files are a unique type of plain file. As the name implies, configuration files contain information about the structure or arrangement of specific parts of the system. They are kept in the /etc directory.

Where is config INI file?

Known is configured through config. ini, a simple file that is stored in the /configuration directory. Usually, config. ini is created automatically during installation.

What is .INI file in Unix?

INI is a configuration file standard. A . conf file could be an INI file, or it could be any other configuration system that the application supports. MySQL, for example, uses the file my. cnf by default for configuration, which is an INI file.


1 Answers

You should adhere your application to the XDG Base Directory Specification. Most answers here are either obsolete or wrong.

Your application should store and load data and configuration files to/from the directories pointed by the following environment variables:

  • $XDG_DATA_HOME (default: "$HOME/.local/share"): user-specific data files.
  • $XDG_CONFIG_HOME (default: "$HOME/.config"): user-specific configuration files.
  • $XDG_DATA_DIRS (default: "/usr/local/share/:/usr/share/"): precedence-ordered set of system data directories.
  • $XDG_CONFIG_DIRS (default: "/etc/xdg"): precedence-ordered set of system configuration directories.
  • $XDG_CACHE_HOME (default: "$HOME/.cache"): user-specific non-essential data files.

You should first determine if the file in question is:

  1. A configuration file ($XDG_CONFIG_HOME:$XDG_CONFIG_DIRS);
  2. A data file ($XDG_DATA_HOME:$XDG_DATA_DIRS); or
  3. A non-essential (cache) file ($XDG_CACHE_HOME).

It is recommended that your application put its files in a subdirectory of the above directories. Usually, something like $XDG_DATA_DIRS/<application>/filename or $XDG_DATA_DIRS/<vendor>/<application>/filename.

When loading, you first try to load the file from the user-specific directories ($XDG_*_HOME) and, if failed, from system directories ($XDG_*_DIRS). When saving, save to user-specific directories only (since the user probably won't have write access to system directories).

For other, more user-oriented directories, refer to the XDG User Directories Specification. It defines directories for the Desktop, downloads, documents, videos, etc.

like image 120
Juliano Avatar answered Sep 22 '22 23:09

Juliano