Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

linux

In my OSGi-based Java app I am developing a bundle to provide the rest of the system with access to the file system. In addition to providing access to the user home directory, I also wish to provide access to a non-user specific area. Exactly what this area will be used for is as yet undetermined, but it will not be for preferences (handled by a different bundle), however it may be used to store data that could change at runtime.

I intend on using the following directories for this purpose:

  • Windows Vista & Windows 7: “\ProgramData”.
  • Windows XP: “\Documents and Settings\All Users“.
  • Mac OS X: “/Library/Application Support”.

Where is a sensible equivalent in Linux and how do I get a handle on it from my Java code?

like image 557
William Avatar asked Oct 02 '09 15:10

William


People also ask

Where does Linux store personal data?

You can store your personal dirs, files in any dirs in it. ~/Documents may be a good place for Projects. ~/Public is normally shared to anyone in the network. So if you do not want to share, put your files in another dirs instead.

What is the srv directory in Linux?

The /srv/ directory contains site-specific data served by your system running Red Hat Enterprise Linux. This directory gives users the location of data files for a particular service, such as FTP, WWW, or CVS. Data that only pertains to a specific user should go in the /home/ directory.

What is data folder in Linux?

Linux Data directory. Data directory is used to store data of the system. Data directory contains following directories.


2 Answers

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.

like image 138
Rob Hruska Avatar answered Sep 21 '22 14:09

Rob Hruska


It depends.

  • Global configuration -> /etc/appname

  • Read-only, independent of machine architecture -> /usr/share/appname

  • Read-only, machine specific -> /usr/lib/appname

  • Read-write -> /var/lib/appname

No guarantee for completeness, please check the Filesystem Hierarchy Standard.

like image 41
starblue Avatar answered Sep 22 '22 14:09

starblue