Understanding the Linux File Hierarchy Standard

by InitializeSahib in Circuits > Linux

2544 Views, 21 Favorites, 0 Comments

Understanding the Linux File Hierarchy Standard

image.jpg

For new Linux users, understanding the FHS (the way files are laid out) is not a trivial task.

You could get confused by / and /root, or maybe you think /dev is a directory for developers, or heck, maybe you don't even know what / is!

This instructable aims to put that all to rest.

NOTE: The folders in this 'structable are from my Ubuntu system. As such, they may not reflect your system's layout.

/: Where the Magic Happens

/ is the core of the FHS. Everything is here. Every folder, every file, every device, every partition, everything is stored in here. Even the variables UEFI keeps track of could be stored in here. There is no limit to what / can store. (Excluding partition sizes, or course!)

/ is pronounced as "root". So, when you say, "I'm going to change this system's / directory," you actually say, "I'm going to change this system's root directory."

/ is not to be confused with /root, which we'll talk about.

/bin and /sbin: Don't Throw It in the /bin, Throw It in /dev/null

(You probably won't get the title.)

/bin is where the critically important programs are kept. By critically important, I mean that if your system is on the verge of dying, you need these programs to run.

/sbin is similar to /bin, but is different in that /sbin stores utilities that are meant for system administrators. (like recreating folders and other system management things)

/dev: Mommy, I Deleted My Keyboard!

/dev stands for device, and as such contains a bunch of files that represent your system's devices.

In UNIX, everything is a file. This carries over to Linux too.

This is why in many commands involving disks you see /dev/sda or something of the sort. That is a device file that represents a hard-disk. Hence why it is included in the disk operations.

/dev also holds many streams, which contain endless amounts of information.

/dev/urandom and /dev/random are for random bytes.

/dev/null is the black hole of Unix. Once something goes it, it cannot escape. (This is why you see so many jokes with /dev/null, it basically equates to "the underworld".)

There are, of course, many more things in /dev.

Admin Tip: If someone ever deletes /dev, you can recreate it with the /sbin/MAKEDEV utility.

/boot: Hit the Road, Jack!

If you edited your partitions, you probably saw something like "/dev/sda1: /boot". This is where /boot comes in.

/boot is incredibly important. Without it, your system wouldn't.... boot. (That's why it's named /boot!)

/boot stores versions of the Linux kernel, initrds, and bootloader files. One single file erased from /boot could destroy your system. (But not brick it.)

/etc: Do You Etc What I Etc?

/etc store system-wide configuration files. This means that every user on the system will have the same config, if it is defined in /etc.

A lot of programs (and system services) have their configuration files in /etc.

Some programs keep their configurations in /home, which is where we're going next.

/home: There's No Place Like It

/home

is the directory where user's directories are stored.

It's like C:\Users from Windows.

For example, if you had Jacob, Alyssa, and John using the same system, you could have /home/jacob, /home/alyssa, and /home/john.


/home also stores user-wide configs, which means only that user has that configuration.

/home has folders for Documents, the Desktop, etc. A person new to Linux will not have to leave /home that much.

/lost+found: Where Did My Shoe Go?

/lost+found is a directory exclusive to some ext filesystems. When you force-shutdown your computer, files that would've been lost otherwise are put into lost+found.

Admin Tip: Don't let users access lost+found. Don't even let yourself access it.

/mnt: Mnt. Everest

/mnt is usually where people manually mount filesystems.

/media is where automatically mounted filesystems are usually stored.

/mnt stands for "mount".

/media: Multimedia

/media contains filesystems, USBS, and cd-roms that were automatically mounted by the system, or mounted by the user without specifying a path.

For example, if I right-click the USB on my desktop, and select "Mount", it mounts it in /media, because I couldn't give it an exact path.

/opt: I Would Like to Opt Out, Please.

/opt

stands for optional. Some programs break the rules and place their files here.

Usually it's for temporary files that need to stay after a reboot.

/proc: Proc-a-doodle-doo

/proc is where processes store their current information.

It is a way for processes to communicate to each other.

Everyone Tip: Don't do anything with /proc.

/root: I Don't Think We're Getting to the Root of the Problem...

/root is the home directory for the root user (superuser). The root user has all the permissions and privileges that the system can give. They can do anything from renaming a file in /etc, to wiping out an entire harddrive.

/sys: My Sys Keeps Nagging Me!

/sys is where your system's files are stored. This includes things like firmware variables.

Everyone Tip: NEVER EVER EVER EVER EVER EVER EVER EVER DO ANYTHING WITH /SYS.

/tmp: It's Fairly Hot Today. the High Will Be 96 Deg- Wrong Temp.

/tmp is where applications keep the temporary files they're using. It is usually mounted as a seperate filesystem, called tmpfs.

Admin Tip: Unless an application is currently using it, it's safe to clear out /tmp.

/usr: Whatever Acronym That Has U, S, and R in It

/usr is usually the largest directory in the filesystem.

It contains many subdirectories:

/usr/bin contains system-wide not-as-important binaries

/usr/local/bin contains binaries that aren't pre-installed (sometimes)

/usr/lib contains libraries required by programs in /usr/bin

/usr/local/lib contains libraries required by programs in /usr/local/bin

/usr/share contains documentation of manuals.

I can't name all of them, so I'll stop there.

Fun Fact: /usr originally had the role of /home, and stored user directories. This is why it was named "usr". Now, it just refers to shared resources, which is why it is usually called "Unix System Resources" or "Unix Shared Resources" or "User System Resources". At this point, /usr doesn't even have an official name. Just name it whatever you want.

/var: Variably Variously Var

/var contains things like system logs, web servers, printer spools, and other miscellaneous things.

It's called var because it contains variable things. It doesn't have specialized things in it like /boot or /etc. It just has.... stuff.

/run: ARE YOU FAST ENOUGH

/run, newly introduced in FHS 3, is the new location for /var/run.

It is similar to /proc in that it contains files that currently running programs need.

/lib: But Where Are the Books?

/lib and /lib64 store libraries used by /bin and /sbin binaries.

On my system, lib64 only has one library, ld.so.1 (or something similar).

This is the dynamic linking library for x64 systems.

x64 libraries are found on my system at /usr/lib/x86_64-linux-gnu and /usr/local/lib/x86_64-linux-gnu.

/end

This isn't a directory. This is just how I say it's the end of things.


It's the end!

Now you can master the FHS!