7

This question says the best place to store settings in linux is in ~/.config/appname

The program I'm writing needs to use a 99MB .dat file for recognizing facial landmarks, embedding it in the binary doesn't seem like a good idea.

Is there some default place to store resources on linux? currently it's just in the directory next to the executable, but this requires that the program is run with the current directory being the directory it's located in.

What's the best way to deal with resources like this on linux? (that could potentially be cross platform with at least OSX)

Community
  • 1
  • 1
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
  • Doesn't `argv[0]` tell you where the program was loaded from? – Mark Ransom Jan 04 '16 at 20:48
  • 1
    @MarkRansom - Not universally. If you happen to be running it via `execl` (or friends), then you can pass in anything you like for `argv[0]`. Will also get confused by symlinks and stuff. – Oliver Charlesworth Jan 04 '16 at 20:50
  • Is it a read only resource or is it user data that gets updated? – Galik Jan 04 '16 at 20:51
  • How is the application distributed? When distributed in source, configure (or friends) usually take care of that. When distributed in packages, it simply uses system-wide directories hardcoded into it. – SergeyA Jan 04 '16 at 20:51
  • 1
    This may be of use: https://www.gnu.org/prep/standards/html_node/Directory-Variables.html – Galik Jan 04 '16 at 20:55
  • Also: http://stackoverflow.com/questions/4158900/embedding-resources-in-executable-using-gcc – genpfault Jan 04 '16 at 21:09

2 Answers2

4

You should take a look at the Filesystem Hierarchy Standards. Depending on the data (will it change, is it constant across all installations, etc) the path where it gets placed will change based on the standards.

In general:

  • /usr/lib/program: includes object files, libraries, and internal binaries for an application
  • /usr/share/program: for all read-only architecture independent data files
  • /var/lib/program: holds state information pertaining to an application or the system

Those seem like pretty good places to start, and you can check the documentation to see if your app falls into one of those categories.

Schiem
  • 589
  • 3
  • 12
0

If the file is specific to the user running the app, it should be in a subdir of ~/ but AFAIK there's no standard, and the best choice depends much on the file type/usage. If it should be visible to the user via GUI, you could use ~/Desktop or ~/Downloads. If it's temporary, you can use ~/tmp or ~/var/tmp.

If it's not specific, you should place it in a subdir of /var. Again, the exact subdir may depend on its kind and other factors.

Fabio Ceconello
  • 15,819
  • 5
  • 38
  • 51