Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux/UNIX install data files

I understand that when installing a C++ command line program on Linux/UNIX, it is customary instead of leaving it in its original directory, to move it to a directory that is already on the path, so I have a make install entry:

mv ayane /usr/local/bin

Looking a bit further ahead, I'm going to end up with a directory or two full of configuration, data and script files, which the program needs to read, some at startup, some later on demand, and in some cases subsequently modify and save again.

This leads to the question of how the program can know where its data files are located. Looking in /bin on my Ubuntu Linux virtual machine, it seems to live up to its name in containing only binary files, so the data files are not typically placed in the same directory as the program.

What's the usual solution for putting data files in a location that can be known to the program?

like image 826
rwallace Avatar asked Sep 23 '09 17:09

rwallace


2 Answers

There are some filesystem standards, reading up on FHS or something like that (note that there are different approaches to filesystem layout).

Basically, you put your executable binaries into $prefix/bin/, per-host configuration goes into $prefix/etc/, per-user into user's home directory, arch-independent static data into $prefix/share, arch-dependent data and libraries into $prefix/lib and the mutable data normally goes into /var/lib/.

It's better to have this stuff configurable both at compile-time and runtime. And it's also customary not to write Makefiles with install targets by hand, you may want to look at the autotools suite or similar (a matter of taste).

like image 194
Michael Krelin - hacker Avatar answered Nov 18 '22 22:11

Michael Krelin - hacker


You should look at the File System Hierarchy standard.

In brief, if you program needs system-wide files, then config should go in /etc. Resources, such as scripts and image files go in /usr/share. Runtime data goes in /var/run.

Per-user files live in the user's home directory, of course.

like image 35
alex tingle Avatar answered Nov 18 '22 21:11

alex tingle