Linux var cache directory

What goes in /var?

I read The Linux Command Line by William Shotts, and there are some descriptions of Linux files (system directories):

The /var directory contents don’t change. This tree is where data that is likely to change is stored. Various databases, spool files, user mail, etc. are located here.

I am wondering: If the /var directory contents are not supposed to change, why is there a www directory in /var/www after installing apache-php ? The /var/www directory is where we must edit, create or delete files. This is a localhost public directory. Why did he say, that the /var directory contents don’t change?

«don’t change. This tree is where data that is likely to change» — the quote is self-contradictory

Is this really what it says in your book? What I can find on page 23 in «The Linux Command Line» version 17.10 by William Shotts makes more sense: «With the exception of /tmp and /home, the directories we have looked at so far remain relatively static, that is, their contents don’t change. The /var directory tree is where data that is likely to change is stored. Various databases, spool files, user mail, etc. are located here.»

5 Answers 5

That description of /var is self-contradictory. /var contains things that are prone to change, such as websites, temporary files ( /var/tmp ) and databases. The name is an abbreviation of «variable».

@Sandeep I think the accepted answer is chosen by the person who asks the question. This person may not have had enough information before they chose an accepted answer. Generally speaking, answers with more votes will help more people. I suggest reading the comments below each answer, and follow any links provided by the answer’s author before making your decision. In my opinion, for this question, the accepted answer is incorrect.

Change can occur in more than one way. Variable files may change in size (footprint) or possibly quantity. Use /var if you have a set number of files which may be growing (i.e. due to log appending or rotation) over time so as not to run out of disk space.

From man hier , which has a «description of the filesystem hierarchy:»

/var This directory contains files which may change in size, such as spool and log files.

/var/account Process accounting logs (optional).

/var/adm This directory is superseded by /var/log and should be a symbolic link to /var/log .

/var/backups Reserved for historical reasons.

/var/cache Data cached for programs.

/var/cache/fonts Locally-generated fonts (optional).

/var/cache/man Locally-formatted man pages (optional).

/var/cache/www WWW proxy or cache data (optional).

/var/cache/ Package specific cache data (optional).

/var/catman/cat7 or /var/cache/man/cat9 These directories contain preformatted manual pages according to their man page section. (The use of preformatted manual pages is deprecated.)

/var/crash System crash dumps (optional).

/var/cron Reserved for historical reasons.

/var/games Variable game data (optional).

/var/lib Variable state information for programs.

/var/lib/hwclock State directory for hwclock (optional).

/var/lib/misc Miscellaneous state data.

/var/lib/xdm X display manager variable data (optional).

/var/lib/ Editor backup files and state (optional).

/var/lib/ These directories must be used for all distribution packaging support.

/var/lib/ State data for packages and subsystems (optional).

/var/lib/ Packaging support files (optional).

/var/local Variable data for /usr/local.

/var/lock Lock files are placed in this directory. The naming convention for device lock files is LCK.. where is the device’s name in the filesystem. The format used is that of HDU UUCP lock files, that is, lock files contain a PID as a 10-byte ASCII decimal number, followed by a newline character.

/var/log Miscellaneous log files.

/var/opt Variable data for /opt .

/var/mail Users’ mailboxes. Replaces /var/spool/mail .

/var/msgs Reserved for historical reasons.

/var/preserve Reserved for historical reasons.

/var/run Run-time variable files, like files holding process identifiers (PIDs) and logged user information (utmp). Files in this directory are usually cleared when the system boots.

/var/spool Spooled (or queued) files for various programs.

/var/spool Spooled (or queued) files for various programs.

/var/spool/at Spooled jobs for at(1) .

/var/spool/cron Spooled jobs for cron(8) .

/var/spool/lpd Spooled files for printing (optional).

/var/spool/lpd/printer Spools for a specific printer (optional).

/var/spool/mail Replaced by /var/mail.

/var/spool/mqueue Queued outgoing mail (optional).

/var/spool/news Spool directory for news (optional).

/var/spool/rwho Spooled files for rwhod(8) (optional).

/var/spool/smail Spooled files for the smail(1) mail delivery program.

/var/spool/uucp Spooled files for uucp(1) (optional).

/var/tmp Like /tmp, this directory holds temporary files stored for an unspecified duration.

/var/yp Database files for NIS, formerly known as the Sun Yellow Pages (YP).

Источник

Читайте также:  Kali linux пакетный менеджер

Where should I put my application cache for Unix-based apps?

I am building a command line application, and I have a need to save some temporary data to files. I do not know where is convention for applications to store their cache on Unix-based systems (in my case, Ubuntu 12.0.4).

2 Answers 2

«Unix based systems» is far too general a category to make any kind of generally-applicable determination that will apply to all Unix based systems. The problem is that the filesystem structure (and the «proper» / «conventional» place to put things) is so wildly different between different flavors of «Unix» (if you can even call it that) that you pretty much have to handle it on a case-by-case basis.

  • On Ubuntu, 64-bit libraries go into /usr/lib or /usr/lib/x86_64-linux/ and 32-bit libraries go into /usr/lib32
  • On Fedora, 64-bit libraries go into /usr/lib64 and 32-bit libraries go into /usr/lib
  • Fedora has no notion of /lib or /bin anymore (they are just symlinks into the equivalent /usr directories)
  • Most Linux distros prefer to install user-installed software (that is, software not provided by the package manager) in /usr/local/ (with lib, bin, etc, var, and so on within /usr/local/)
  • Many Linux distros use /var/cache for cache, although if it’s «transient» (doesn’t matter if it gets lost), it can be stored in /tmp
  • Some «app in a folder» type applications store everything in a subdirectory of /opt (especially clickwrap installers)
  • Some apps just install into a subdirectory of the user’s ~ directory (usually /home/username)
  • On Solaris, I’ve seen /srv used similarly to /opt, or sometimes /srv is the www-root
Читайте также:  Флешка linux сохранение данных

The answer is that the canonical, socially acceptable, well-integrated convention for where to store anything on any operating system, whether it’s a distro of Linux, BSD, Solaris, HP-UX, etc. is dependent on the exact circumstances. Specifically:

  • How is the package distributed?
  • Does the user require root access to install it?
  • Does the package depend on or integrate directly with other packages already on the system, e.g. a plugin or add-on?
  • Is the package going to be integrated into the distribution’s upstream repositories, so that users can use a command like apt-get or yum to install it directly without downloading an installer off a website?
  • Will the software have separate configuration for each different user who operates the computer?
  • Will the software have global configuration settings that should only be modifiable by the administrator (root)?
  • Does the software need to integrate with the init system (e.g. to start on boot)?

There is no straight answer for this without considering all the factors. However, for Ubuntu 12.04 specifically, if you are building your package into a .deb file to be distributed in a PPA or for submitting to Ubuntu’s own package repositores ( main or universe ), I would recommend that cache should be stored in /var/cache . But that is only for Ubuntu and you should certainly not apply the assumption that every distro or Unix-based OS will consider this acceptable.

Furthermore, if there are no advantages to saving the cache data across boots of the system, I think it could also belong in /tmp.

Note that you are going to run into these pathing convention problems for every type of file that your program uses: shared data, executable files, libraries, help files, images, sound, web pages, and on and on. So I have to wonder, if you are asking about cache files, how you are planning to handle the other file types. Are you just making naive assumptions and hoping that no one disagrees with you? If you haven’t read any Ubuntu docs or standards suggesting where to put them, it is a bad idea to just assume one thing or another. For example, always sticking libraries in /usr/lib could be a mistake, as depending on the situation they may belong elsewhere.

Читайте также:  Linux видеокарты nvidia intel

Additionally, as a software developer, I think the most responsible thing to do is allow the end-user to decide where to put their files. You can set defaults, but users (and distributors) can and will customize the build to fit with their distro.

The easiest way to do this is to build your program using GNU Autoconf. Autoconf is a build system where the user can pass command-line arguments to the build script to change the paths of the various «directory types» away from the defaults. Almost every distribution has a build script for every Autoconf package that sets the distro-appropriate conventional directories for each type. They even specifically have a directory type for cache: sharedstatedir.

Источник

Оцените статью
Adblock
detector