73

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?

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
dasdasdasdasd
  • 1,249
  • 2
  • 11
  • 13
  • 12
    "*don't change*. This tree is where data that is *likely to change*" - the quote is self-contradictory – Marisha Oct 14 '19 at 01:52
  • 8
    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." – Matthias Braun Jan 12 '21 at 16:38

5 Answers5

110

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".

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • 1
    The accepted answer and this are conflicting each other. but this has more votes. can any one help!! – Sandeep Aug 18 '17 at 06:43
  • 6
    @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. – Jonathan Sep 10 '18 at 13:06
  • 1
    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. – vhs Mar 23 '19 at 02:25
51

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> Package specific cache data (optional).

/var/catman/cat[1-9] or /var/cache/man/cat[1-9] 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> Editor backup files and state (optional).

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

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

/var/lib/<pkgtool> 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..<device> where <device> 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).

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
nelaaro
  • 3,006
  • 5
  • 38
  • 56
17

The definition of various files (including directories) which are expected to be available is given by the Linux File-system Hierarchy Standard and the Linux Standard Base. The /var hierarchy

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

Interestingly /var/www/ is not defined in such normative specifications.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

I read some description about /var in linfo.org:

Among the various subdirectories within /var are /var/cache (contains cached data from application programs), /var/games (contains variable data relating to games in /usr), /var/lib (contains dynamic data libraries and files), /var/lock (contains lock files created by programs to indicate that they are using a particular file or device), /var/log (contains log files), /var/run (contains PIDs and other system information that is valid until the system is booted again) and /var/spool (contains mail, news and printer queues).

-22

I'd say that the contents in /var don't change so often. In my experience it's mostly used to store database files, cache files and of course, the /var/www directory. These objects do change but for example, a website doesn't change every second.

akumapunk
  • 32
  • 3
  • 22
    But it also holds things like `/var/log` which, on busy systems, can be changing significantly on a sub-second time scale... – twalberg Aug 29 '13 at 16:22