Linux directory structure

From Christoph's Personal Wiki
Jump to: navigation, search

The Filesystem Hierarchy Standard (FHS) defines the main directories and their contents in Linux operating systems. More simply, it is the Linux directory structure.

Directory structure

All files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a *nix system depending on whether certain subsystems, such as the X Window System, are installed.

Directory Description
/bin/ Essential command binaries for all users (e.g., cat, ls, cp)
/boot/ Boot loader files (e.g., kernels, initrd)
/dev/ Essential devices (e.g., /dev/null)
/etc/ Host-specific system-wide configuration files.
Configuration files for /opt/
Configuration files for the X Window System, version 11
Configuration files for SGML.
Configuration files for XML.
/home/ Users' home directories.
/lib/ Libraries essential for the binaries in /bin/ and /sbin/
/mnt/ Temporarily mounted filesystems.
/media/ Mount points for removable media such as CD-ROMs (appeared in FHS-2.3)
/opt/ Add-on application software packages.
/proc/ Virtual filesystem documenting kernel and process status, mostly text files (e.g., uptime, network)
/root/ Home directory for the root user.
/sbin/ System administrative binaries (e.g., init, route, ifup) (system binaries)
/tmp/ Temporary files. (See also /var/tmp)
/srv/ Site-specific data which is served by the system.
/usr/ Secondary hierarchy for user shareable, read-only data.
Same as for top-level hierarchy, but non-essential (not needed to bring the system up or recover after problems).
Standard include files.
Same as for top-level hierarchy.
Same as for top-level hierarchy, but non-essential (e.g. daemons for various network-services).
Architecture-independent (shared) data.
Source code. (e.g. the kernel source code with its header files)
X Window System, Version 11 Release 6.
Tertiary hierarchy for local data, specific to this host.
/var/ Variable files, such as logs, databases, websites, and temporary e-mail files.
Lock files. Files keeping track of resources currently in use.
Log files. Various logs.
Users mail-boxes.
Information about the running system since last boot. (e.g. currently logged-in users and running daemons)
Spool for tasks waiting to be processed. (e.g. print queues and unread mail)
Deprecated location for users mail-boxes.
Temporary files. Preferred to /tmp once in multi-user mode.




/tmp nosuid,noexec,nodev (no SUID programes, No executables, No Device Files).
/var noexec,nosuid # maybe
/usr/local # maybe

If you do not want run-away logging to fill up our /var partition, you can archive (tar) old logs (e.g., older than one day):

find /var/log/ -name "*.log" -mtime +1 -exec bzip2 -z '{}' \;

and then delete old tars (e.g., older than 30 days):

find /var/log -name "*.bz2" -mtime +30 -exec rm '{}' \;
  • "Mountable" directories are: '/home', '/mnt', '/tmp', '/usr', and '/var'.
  • Essential for booting are (i.e., they should all be on one partition): '/bin', '/boot', '/dev', '/etc', '/lib', '/proc', and '/sbin'.

man pages

The following directories are usually (actually, should be) in /usr/share/<mandir>/<locale>

User programs (optional)
System calls (optional)
Library calls (optional)
Special files (optional)
File formats (optional)
Games (optional)
Miscellaneous (optional)
System administration (optional)

Create the FHS from scratch

Note: The following was taken from the Linux From Scratch docs.

mkdir -pv /{bin,boot,etc/{opt,sysconfig},home,lib/firmware,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -v  /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -v  /usr/libexec
mkdir -pv /usr/{,local/}share/man/man{1..8}

case $(uname -m) in
 x86_64) ln -sv lib /lib64
         ln -sv lib /usr/lib64
         ln -sv lib /usr/local/lib64 ;;

mkdir -v /var/{log,mail,spool}
ln -sv /run /var/run
ln -sv /run/lock /var/lock
mkdir -pv /var/{opt,cache,lib/{color,misc,locate},local}

External links