The File System

I compiled this story by taking information from the Linux Filesystem Hierarchy Standard and editing it and subtracting about 90% of the FHS and adding my own understanding of the truth about Linux. I’ve also added information from other sources, as noted.

Its a learning experience for me and a lesson in my holistic healing and teaching enterprise, for anyone interested in learning how to develop your own personal cloud of artificial intelligence. Its really just a primer, designed to help you find your way in your self-directed exploration of Linux and other free and open source software.

The ls command will show you your home directory. ls / will show you the Linux file system on your computer. Browse around in there. Be careful. Don’t change anything that you don’t understand. Just look around.

etc is where you will find the configuration files that you can edit, to configure your applications the way you want them. Usually its best to create a file.d file that will override your configuration file, rather than directly editing your configuration files. That way, your configuration settings are not over-written when that application is updated.

Create a Dot-files directory in your home directory, and in at least one external hard drive of some kind, where you can copy all your configuration files. Then, whenever you install Linux on a computer, you can copy and paste your configuration files into your new Linux machine.

Filesystem Hierarchy Standard

Some files are sharable, some are not. Some files are static and others are variable. Sharable files can be stored on one host and used on another. Unsharable files cannot be shared.

Static files are binaries, libraries, documentation files and others that do not change, unless you change them. Variable files are files that the operating system changes while it is operating.

Linux File System

Directory    Description
bin          Essential command binaries
boot         Static files of the boot loader
dev          Device files
etc          Host-specific system configuration
lib          Essential shared libraries and kernel modules
media        Mount point for removable media
mnt          Mount point for mounting a filesystem temporarily
opt          Add-on application software packages
run          Data relevant to running processes
sbin         Essential system binaries
srv          Data for services provided by this system
tmp          Temporary files
usr          Secondary hierarchy
var          Variable data

root

/ – is your root filesystem. It must be able to boot, restore, recover and/or repair the system. It needs to be able to mount other file systems. It includes boot loader information, configuration files, utilities and other essential start-up data.

Keep your root filesystem as small as possible, to make it more compatible with other systems and easier to repair. /usr/, /opt/ and /var/ can be located on another partition or filesystem.

boot

/boot/ – Contains static files of the boot loader. Everything required for the boot process is contained in /boot/, except configuration files not needed at boot time and the map installer.

/boot/ stores data that is used before the kernel begins executing user-mode programs. The operating system kernel must be located in either / or /boot/.

/efi/ – Sometimes EFI System Partition (ESP) is separate from /boot/. On my KDE Neon system, /efi/ is located within the /boot/ directory, as in, /boot/efi/. Same with Kubuntu, naturally.

http://www.linuxbase.org/betaspecs/fhs/fhs.html

bin

/bin/ is a sub-directory of the root directory in Linux that contains the executable (ready to run) programs necessary for booting and repairing the operating system. This where Linux runs.

No sub-directories are allowed in /bin/. It contains commands that are used by all users and are required when no other filesystem is mounted (single user mode).

Command binaries that are not essential enough to be in /bin/, should be placed in /usr/bin/ instead. Items that are only required by non-root users, such as the X Window System, chsh, etc., are generally not essential enough to be placed into the root partition.

etc

/etc/ is where your host specific system configuration files go. Configuration files are local files, which are static and not executable binaries, and are used to control the operation of a program. This is where you can customize your LInux operating system.

/etc/ may contain executable scripts, such as the command scripts commonly called by systemd to start and shut down the system and to start daemon processes. “Executable binary” in this context refers to direct machine code or pseudocode in a non-human-readable format, such as native ELF executables.

Files should be stored in sub-directories of /etc/, rather than directly in /etc/. Host-specific configuration files for application software packages that you install on your computer must be installed in the /etc/opt/ directory. The static data for packages are stored in a sub-tree with the same name as the package in /etc/opt/.

If the package or system needs it to be in a different location in order to function properly, the configuration files may be somewhere other than /etc/opt/.

Your Home Directory

/home/ – is a site-specific filesystem, containing a home directory for each individual user. Programs should query for the location of the home directory, rather than assume any specific location for it.

Your Dolphin file manager displays your home directory by default. User specific configuration files for applications, are stored in a “dot file or .file” in your home directory.

Dot files are files that are not displayed by default. You can set Dolphin to display them in the tool bar under view. You can display them in your terminal with the command ls -a. The -a switch tells your terminal to display all files and directories.

Applications that need to create more than one .dot file should place them in a “dot directory, ie., .directory”, a sub-directory with a name starting with a ‘.’ character. Files contained in a .directory should not be .files.

Applications that you install may want to place files and directories in your home directory. They should follow the following basic structure. Some of these directories are also standardized, though more weakly, by the XDG Base Directory Specification. Additional locations for high-level user resources are defined by xdg-user-dirs.

The tilda, ~, in the following sections signifies your home directory.

~/.cache/ – contains persistent user cache data. Applications may place non-essential data in this directory. Flushing this directory should not effect the operation of programs, other than slowing them down while they rebuild the cache. If an application finds $XDG_CACHE_HOME set, it should use the directory specified in it, instead of this directory.

~/.config/ – contains application configuration and state files. When a new user is created, this directory will be empty or not exist at all. Applications should fall back to defaults if their configuration or state in this directory is missing. If an application finds $XDG_CONFIG_HOME set, it should use the directory specified in it, instead of this directory.

~/.local/bin/ – contains executables that appear in the user’s $PATH search path. Placing executables in this directory, which you cannot execute from a shell, is not recommended. They should be placed in a sub-directory of ~/.local/lib/ instead.

~/.local/lib/ – contains static, private vendor data that is compatible with all architectures.

~/.local/lib/arch-id/ – contains the location for placing public dynamic libraries.

~/.local/share/ – contains resources shared between multiple packages, such as fonts or artwork. Usually, the precise location and format of files stored below this directory is subject to specifications that ensure interoperability. If an application finds $XDG_DATA_HOME set, it should use the directory specified in it, instead of this directory.

/root/ – is the home directory for the root account. It may be determined by distribution developer or by local preference, but this is the recommended default location.

srv

/srv/ – contains site-specific data which is served by your system.

This enables users to find the location of the data files for a particular service. Its also a good place for services which require a single tree for read-only data, writable data and scripts (such as cgi scripts).

Data that only you are interested in, should go in your home directory. If you do not want the directory and file structure of the data to be exposed to your customers, it should go in /var/lib/.

One way of structuring data under /srv/ is by protocol, as in, ftp, rsync, www, and cvs. On large systems it can be useful to structure /srv/ by administrative context, such as /srv/physics/www/, /srv/compsci/cvs/, etc.

This setup will differ from host to host. Therefore, no program should rely on a specific sub-directory structure of /srv/ or on any data necessarily being stored in /srv/. However, /srv/ should always exist on FHS compliant systems and should be used as the default location for such data.

tmp

/tmp/ – must be made available for programs that require temporary files. Programs must not assume that any files or directories in /tmp/ are preserved between instances of the program.

Although data stored in /tmp/ may be deleted in a site-specific manner, it is recommended that files and directories located in /tmp/ be deleted whenever the system is booted.

run

/run/ – contains system information data, describing the system since it was booted. Files under this directory must be cleared at the beginning of the boot process.

Programs that use more than one run-time file can use sub-directories in /run/. Users may also have sub-directories of /run/.

Process identifier (PID) files must be placed in /run/.

/run/log/ – system components may place private logs in this directory. It is always writable.

/run/user/ – contains user runtime directories for each individual user. They are usually individually mounted instances of “tmpfs”. They are always writable and flushed during reboot and whenever the user logs out.

usr

The usr hierarchy contains vender supplied operating system resources

/usr/ contains shareable, read-only data. Information that is host-specific or information that changes over time, is stored elsewhere. Large software packages must not use a direct sub-directory under the /usr/ hierarchy.

/usr/bin/ – contains most user commands. It is the primary directory for executable commands on your system. There cannot be any sub-directories in /usr/bin.

/usr/include/ – contains standard include files. It is where all of the system’s general-use include files for the C programming language should be placed.

/usr/lib/ – contains libraries for programming and packages, includes object files and libraries. It may also include internal binaries that are not intended to be executed directly by users or shell scripts.

Applications may use a single sub-directory under /usr/lib/. If an application uses a sub-directory, all architecture-dependent data used exclusively by the application must be placed within that sub-directory.

/usr/local/ – Use the /usr/local/ hierarchy when installing software. It needs to be secured against being overwritten, when the system software is updated.

/usr/share/ – contains architecture-independent data, for all read-only architecture independent data files.

var

The /var/ hierarchy contains persistent, variable system data.

/var/tmp/ – contains temporary files preserved between system reboots

/var/yp/ – contains Network Information Service (NIS) database files (optional)

/var/ contains variable data files, including spool directories and files, administrative and logging data, and transient and temporary files.

Some parts of /var/ are not shareable between different systems. For instance, /var/log/, /var/lock/, and /var/run/ are not shareable. Other parts are shareable, notably /var/mail/, /var/cache/man/, /var/cache/fonts/, and /var/spool/news/.

dev

/dev/ – contains device files, virtual kernel and API file systems

Special or device files are located in /dev/. It must contain a command named MAKEDEV, for creating devices manually.

The root directory for device nodes, usually mounted as an instance of “devtmpfs”, may be different in sand-boxed or containerized setups. The operating system kernel and systemd-udevd jointly manage this directory. Special purpose file systems may be mounted in the /dev/ directory.

proc

/proc/ – is a virtual kernel file system, exposing the process list and other functionality. /proc/ is primarily an API for interfacing with the kernel and not a place for normal files.

sys

/sys/ – is a virtual kernel file system, exposing discovered devices and other functionality. It is also, primarily an API for interfacing with the kernel and not a place for normal files. Special purpose virtual file systems may be mounted in this directory. /sys/ is usually mounted read only in containerized setups.

lib

/lib/ – contains essential shared libraries and kernel modules, including the shared library images needed to boot the system and run the commands in the root filesystem, such as binaries in /bin/ and /sbin/.

The modules, loadable kernel modules (optional), directories, or symbolic links to it, must be in /lib/, if the corresponding subsystem is installed.

media

/media/ – contains sub-directories used as mount points for removable media such as USB, DVD and zip disks.

mnt

/mnt/ – is a mount point for temporarily mounting a filesystem. You can use it to mount a temporary filesystem as needed. It cannot be used by installation programs. A suitable temporary directory, which is not being used by the system, must be used for that. The content of /mnt/ is a local issue and should not affect the way any program runs.

opt

/opt/ – contains add-on application software packages that you’ve installed.

/opt/bin/, /opt/doc/, /opt/include/, /opt/info/, /opt/lib/, and /opt/man/ are reserved for you to use. Packages may include “front-end” files that you can place (by linking or copying) in these reserved directories. The package must function normally in the absence of these reserved directories.

Variable package files, which change during normal operation, must be installed in /var/opt/. Host-specific configuration files must be installed in /etc/opt/.

No package files may exist outside of the /opt/, /var/opt/, and /etc/opt/ hierarchies, other than the package files that must reside in specific locations within the filesystem tree, in order to function properly. For example, device lock files must be placed in /var/lock/ and device drivers must be located in /dev/.

Generally, all data required to support a package on a system, must be present within /opt/, including files intended to be copied into /etc/opt/ and /var/opt/, as well as reserved directories in /opt/.

sbin

/sbin/ – contains system binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin/.

Utilities used for system administration, and other root-only commands, are stored in /sbin/, /usr/sbin/, and /usr/local/sbin/. / Programs executed after /usr/ is known to be mounted, are generally placed in /usr/sbin/. System administration programs that you install, should be placed in /usr/local/sbin/.

There must be no subdirectories in /sbin/.