Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm making an application that reads/writes to files in the ~/.config folder; however, I want to make sure it works under all systems. Is .config called other things for different system languages? Is there a better way of accessing its value than using a hardcoded .config string? (a la an environment variable)

What is the best practice for this? If there is no established best practice, what is the simplest approach that guarantees the desired result?

share|improve this question
    
Why not make your own folder specific to your own app. ~/.myapp –  Ed Manet Feb 19 '13 at 19:44
2  
When asking questions please use a proper, concise title, and not something like "~/.config folder". –  RolandiXor Feb 19 '13 at 19:59
1  
@EdManet: this would pollute the home directory. I remember the days before XDG was widely supported, and my home directory was really a mess. To be honest, my home directory is still messy because of applications that do not follow XDG. –  Andrea Corbellini Feb 19 '13 at 20:31
    
@RolandiXor sorry, I'm used to posting on StackOverflow, where expressive titles are discouraged (at least my titles are regularly pruned of meaning). I'll remember that this community welcomes sane titles. :) –  weberc2 Feb 19 '13 at 20:47

2 Answers 2

up vote 7 down vote accepted

That configuration directory is specified by the XDG Base Directory Specification standard.

The answer to your question is in the Environment variables section:

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

Be sure to also read Basics, to ensure that you are using the right directories for the right files.

You may also want to know what to do when $HOME is not set. This is not specified by XDG, however what some applications do is to throw an error and exit. Alternatively, you can get the current user ID via getuid(2) and use getpwuid(3) to extract the home directory.

share|improve this answer
    
Thanks, that answers my question perfectly –  weberc2 Feb 19 '13 at 20:48

It's part of the XDG Base Directory Specification:

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.