Filesystem Hierarchy Standard
FHS is the standard method of laying out the directory structure in Linux distributions, so that the contents follow a standard layout. That you can always depend upon certain types of files being in certain types of directories, and that they are generally consistent accross distributions.
Some systems may deviate from FHS in some areas. The current FHS is v2.3, was actually announced Jan 29th, 2004. v3 has been under development for almost 5 years. It stands to reason that some Linux file systems or dirs may have developed over the last ten years use of Linux that don’t quite fit this FHS standard.
Please note that OSX is not FHS-compliant. I’ve added screenshots because i’m a Mac user and am interested in seeing the similarities and differences with Linux.
file system structure on Ubuntu
file system structure on Mac
You can do
man hier to get help and explanations concerning the layout of filesystems. This command works on both Linux and Mac
/entire System hierarchy, primary hierarchy
/binCommand binaries and other executable files
/bootBoot files, boot loaders, kernel
/cdromMount point for CD ROMs
/etcSystem Configuration files
/homeUser Home directories
/mediaRemoveable media, like CDs
/mntMounted devices and disks
/optOptional or third party sofwtare
/procProvides info about running processes
/rootHome dir for the root user
/sbinSystem administration binaries
/tmpTemporary space, typically cleared on reboot
/usrUser realted programs, binaries and docs
/usr/binmost of our executable progarms live here
/usr/sbinsystem adminisration programs
/usr/localLocally installed software that is not part of the base OS
/usr/share/manman pages reside here
/varVariable data, most notably log files
/ aka root is the top of your file system. Do not confuse this with
/root because /root is the home user directory of the root user. Do not store files in
Essential command binaries and executable programs. These need to be available to all users, if you run in Single User Mode. Anything (command) that you might need, whether it is
cat, these commands are gonna be in the /bin directory for any Linux distribution that complies with FSH.
If you’re booting in Single User Mode to recover your system, you’re going to need the binaries in /bin.
They are called binaries because machine reads binary code, which is ones and zeros.
Programs are written in source code and this is human readable text. These text files are then compiled in to machine readable binaries.
/bin on Linux
/bin on Mac
Boot files: boot loaders, initrd files, kernel files etc. These are files that are necessary for the kernel to pass into the boot stage from the grub boot loader
Device directory. These are essential devices. /dev/null, /dev/random, /dev/urandom.. These are the devices that are actually on our system. Our hard drives, CD ROMs etc.
For example, you may have the first hard drive as /dev/sda/, the second as /dev/sdb/ and so on. If they have partitions they’d even have furthermore numbers that’d follow them , like /dev/sda1/ /dev/sda2/ etc.
In Linux, devices are treated as files and you can write them as such.
There are actually two sorts of device files that can be stored in /dev/ folder. Character oriented and Block type. Character oriented device files are used for devices that send or receive data sequentially, one character at a time. Like printers. Block oriented device files manage data in what is known as blocks. Like your actual hard drive, USB drives etc.
Host system specific configuration file directory. Most of these are text files and can be edited using a text editor.
/etc on Linux
Apache conf (Ubuntu):
Apache conf (CentOS):
It inculdes backronyms such as editable text configurations and extended tool chest. You’ll find all of the configuration of run level files that you need to configure for your system from the boot up and boot devices that are connected to the run levels of your system.
Condig files for X Windows systems and your root documents.
User home dirs. Typically with Linux distros, it’s the (only) place where you have write perms by default.
Essential libraries (dependencies?) for all of our binaries that are in /bin and /sbin
Temporarily mounted file systems. Removable media, an extenral USB drive e.g. Linux distros that have /media include OpenSUSE, Fedora and Debian Ubuntu
The mount directory is used by some Linux distros to mount other external devices like CD-drives, DVD drives, USB drives and so on.
Optional applciation software packages, or third party software. Things that we have insatlled. Software that do not come with the OS. For example, Google Earth
All of the info for ecerything inculding our kernel core, IO ports as well as references to all the running PIDs on the system.
/proc is actually a pseudo filesystem that is dynamically created whenever it is actually accessed. Within our /proc directories there are furthermore sub-directories and each of these sub-directories is identifiable with a number and not a name. That number is a PID (Process ID) number. The directory stands for a process. (You can check PIDs with the
ps ax command)
There are also other files in this /proc folder, like /proc/cpuinfo that might be of interest
Home dir for root user. This is usually at the base of the file system instead of in /home/root like the home directories for normal users
Similar to /bin, only the /sbin folder conatins essential system management and administration files/bianries. This includes utilities such as
halt etc. All administrator users will need these binaries at some point.
Site specific data served by the system. Contains sub-dirs for services running on our system such as httpd for apache or ftpd for FTP
The /sys folder contains info about hardware that is on our system
Temporary space, typically cleared on reboot. all of our users have read/write access to /tmp.
The /usr directory contains application files. Most of the application files used on our system are stored in a sub-dir of the /usr dir.
/usr/binis where most of our executable programs live
/usr/libis library files for the application in /usr/bin
/usr/lib64is similar to
/usr/lib, however it only contains 64-bit libraries
/usr/localis locally insalled software that we have cerated (installed?) ourselves.
/usr/bin, only that it contains system administration programs
/usr/shareis where the documentation and man pages reside
Secondary hierarchy, read-only user data. Contains the majority of multi-user.
/usr conatins software applications and all the files necessary to run them (aka dependencies).
It’s the biggest dir on the file system. It’s recommended giving it it’s own partition.
Variable files. Log files, spool dir for printing, run files etc.
Stores all of your restored files that would’ve been lost after a system crashes or something strange happens.. e.g. kernel panics
Every partition has a lost+found in it’s upper directory.
- try to follow the naming convention when creating your files: lowercase, no spaces, slashes or astericks.
- Remember, files that begin with a
Application Directory Structure
Software that you install is usually installed in
/usr/local/PROGRAM/bin /usr/local/PROGRAM/etc /usr/local/PROGRAM/lib /usr/local/PROGRAM/log
OR in a fodler in
/opt/. The folder name could be the program’s name or the company’s name. Like in Windows they have the Adobe folder for Adobe software.
/opt/PROGRAM/bin /opt/PROGRAM/etc /opt/PROGRAM/lib /opt/PROGRAM/log
/opt/COMPANY /opt/COMPANY/bin /opt/COMPANY/etc
/opt/ using both company and program names as folders.
/opt/google /opt/google/chrome /opt/google/earth
/etc/opt/PROGRAM => Config files /opt/PROGRAM/etc /opt/PROGRAM/lib /var/opt/PROGRAM => Log files
/usr/local/bin/PROGRAM /usr/local/etc/PROGRAM.conf /usr/local/lib/libPROGRAM.so