Where to Store Application Data (Non-User Specific) on Linux

Where to store application data (non-user specific) on Linux

It depends on what kind of data you're planning on storing. This answer is under the premise that you're storing and modifying data at runtime.

Contrary to what others have suggested, I would recommend against using /usr/share for storage. From the Filesystem Hierarchy Standard:

The /usr/share hierarchy is for all
read-only architecture independent
data files.

As you're modifying data, this goes against the read-only nature of the /usr subsystem.

A seemingly better place to store your application state data would be /var, or more specifically, /var/lib. This also comes from the Hierarchy Standard. You could create a /var/lib/myapp, or if you're also using things like lock files or logs, you could leverage /var/lock or /var/log.

Have a deeper look at the standard as a whole (linked to above) - you might find a place that fits what you want to do even better.

Like Steve K, I would also recommend using the Preferences API for application preference data.

Linux: where can I store data secretly in order to implement a time-limited demo?

Well after doing quite a bit more research I've concluded that the only place to put that kind of data is /var/tmp. Not exactly secret or obfuscated, but there's no other place in the filesystem that's globally writable and isn't cleared out after rebooting the system.

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

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

  • ~/.config (config, often instead of ~ as it reduces clutter in the user's home directory).
  • ~ (config)
  • /etc
    (config)
  • /var (data)
  • /usr (data)
  • 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.

Where is the best path to store desktop applications data on each OS?

Usually games or apps whose data is to be stored,and not deleted even after uninstalling the app itself,is stored in the users own path:

C:/Users/username/appdata

The appdata directory is hidden so you can either go there from cmd,or unhide it from:

folder options(search in windows tab)/view

Hope this was useful.

Platform-independent way to get a path to store program data

The system property user.home should be pretty standard across most desktop systems.

System.out.println(System.getProperty("user.home"));

Note that this is the user the Java process runs under - so in case of server-side Java process, you would need to store information for the users of your app in your own data structure, as your app's users are not known to the OS.

Regarding a system-wide storage location, you may need to detect the OS version and compute the path. Another problem is that you would most likely need to escalate privileges to write to a system-wide location.

Where do Linux daemons store their data files?

Variable data files are stored under /var. It is beyond the scope of an SE answer to describe the various sub-directories and the uses that the programmer and administrator of a daemon may make of them.

Linux Filesystem Hierarchy Standard version 3, section 5.1 says

/var contains variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files.



Related Topics



Leave a reply



Submit