简体   繁体   中英

Where to save configuration/data files on GNU/Linux?

I have found out, that I can execute my own programs easily by moving them into the /bin file. But I also have seen, that a lot of programs there only consist of one single file that does one simple task and dont needs to save anything in a file.

If I want to write a command line program that also needs to save it's values in a file (for example a little text based game that stores the progress of the player) where the program should store it's data?

There are several dedicated locations in Linux. I want to find out which location is most suitable for, for example, games that need data such as image files and text files and that need to store the progress of the player.

There's plenty of places that configuration/data files etc could be saved:

  • /var (data)
  • /usr (data)
  • /etc (config)
  • ~ (config)
  • ~/.config (config, often instead of ~ as it reduces clutter in the user's home directory).
  • likely many more...

In-depth descriptions of the purposes of the various subfolders of the top-level directories can be found at the links above.


I believe the ad-hoc standard is to use ~/.config for user-specific config files, /var for data files generated during execution, and /etc for "static" system-wide configs. /usr is used for storing user programs and their static data.

More formal standards do exist - the Filesystem Hierarchy Standard expresses the purpose of the top-level directories, while ~/.config is the preferred configuration folder for XDG , and seems to have caught on.

Another suggestion: ~/.local/share is usually more appropriate for application data that the user should not touch. ~/.config is typically for user-modifiable configuration.

You should also use the appropriate environment variables, $XDG_DATA_HOME for ~/.local/share and $XDG_CONFIG_HOME for ~/.config . Some users like to remap these directories to other locations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM