- In this video, we are going to explore
the Linux filesystem hierarchy.
So before we do so, why are files that important?
Well, it's easy to understand.
On Linux, everything is a file.
You want to access your hard disk?
It's a file.
Everything is a file.
So the ability to work with files is really key
to mastering Linux.
Also, configuration is stored
in mostly ASCII text configuration files.
So if you know how to deal with files,
then you can create configurations, and that's convenient.
Devices are addressed by using device files as well.
And in order to define where your files should end up,
there is the Linux filesystem
as defined in the Linux Filesystem Hierarchy Standard.
So the good thing is that directories
are highly standardized on Linux.
Doesn't really matter which distribution you are on.
You will always find the /usr directory.
Now that we talk about it, let me explain what it is.
/usr is for your program files.
So that is where you will find all the commands
that you are using in a Linux environment.
There's a /var directory, that's the directory
that different services are using
to dynamically create files.
/var/log, for instance, contains your log files,
and if anything needs to be cached,
big chance that it is written to /var/cache.
There's the /etc directory.
The /etc directory is what contains
your configuration files.
So if you're looking for configuration, big chance
that it is in the /etc directory.
Now the nice thing about this Linux filesystem is
that the file system is defined
in the Filesystem Hierarchy Standard.
I included the link to linuxfoundation.org.
Now, what is Linux Foundation?
Well, Linux Foundation is the organization behind Linux.
All the Linux distributions are a member of Linux Foundation
and Linux Foundation defines how stuff should happen.
And one of the important things is
the FHS or Filesystem Hierarchy Standard.
Actually, it also exists
as a man page on many Linux distributions,
and that is what I'm going to show you in just a minute.
Now, talking about these directories, you should notice
that the regular users have write access
to just two directories, which are /home and /tmp.
Just to make sure we understand one another,
/home, which contains their own home directory,
a user can write to their own home directory,
not to anybody else's,
and a /tmp directory is a traditional location
where everybody can create files.
Now, write ability on Linux is sometimes pretty frustrating
if you're new to Linux.
So if you're looking for an easy way to verify
if you can write, use a touch command.
touch filename will allow you to verify write access.
It creates a file in a specific location.
Now let's go check this out.
All right, to start with,
I'm showing you man hier.
hier is for the filesystem hierarchy.
There we go.
This is a filesystem hierarchy as defined
by the Linux Foundation.
And if in any case you think,
oh, what is this or that directory used for?
You can see it is pretty specific and details
what is happening in the filesystem hierarchy.
Now I would like to
to show you the directories in the route.
So I'm going to use cd / to go
to the root directory, the root directory of this system,
and I'm using ls - l so that we can see what is going on.
And what do we see?
Well, we see the different directories that exists,
and hey, there is even a new directory, afs.
Just wondering, man hier do we have afs?
afs is so new that it's not
in the filesystem hierarchy, and you know what?
That means that we can safely ignore it for now.
Let's have a look at the directories that do matter.
To start with this one, bin.
bin in Linux stands for binary,
and a binary is a command, a command file,
a program file that can be used by ordinary users.
Likewise, there is sbin.
sbin is a system binary.
You need pseudo privileges in order to use that.
An interesting thing here is going on
and that is that bin is pointing to usr/bin.
That's what we call a symbolic link.
The thing is that in the past
the bin directory had its function.
Nowadays, the bin directory doesn't have a function anymore
according to the filesystem hierarchy,
and everything that in the past was stored
in bin, nowadays, should be stored in usr/bin.
And this symbolic link makes that if you're using any script
or anything else that is still referring to bin,
you automatically end up in usr/bin,
which is the appropriate location.
Now related to bin and sbin,
we also have lib and lib64, which is about libraries.
These are the libraries, belonging
to the files in bin and sbin.
Then we have boot.
boot contains everything that you need to boot.
If you check the contents of boot, then, what do we see?
We see files like, where is it? vmlinux.
vmlinux, that's your Linux kernel.
That's the heart of the operating system
and other stuff that is needed
to boot your system is right there.
Then we have the dev directory
and the dev directory is where you will find devices.
Devices is what allows you to access your hardware,
and one famous device that I want to talk about is sda.
sda typically is your primary hard disk,
or sr0, which is your primary,
which is your CDROM, your optical device.
We will talk about these devices later,
but let's not do that now.
Let's have a look at etc.
So what do we find in etc?
Text-based configuration files.
That's the nice thing about Linux.
Anything you do on Linux is stored
in a text-based configuration files.
For instance, if we do cat on etc/passwd,
that's the user database, and we can see all the users
currently existing on the system.
More about users later.
Back to these directories, what else do we have?
We have home.
So ls on /home is showing
that there is the home directory
for the one and only user on this system.
Then we have media and mnt.
media and mnt is for mounting stuff.
Now, what is mounting stuff?
Mount is what you use
on Linux to connect a specific device to a directory.
I will also explain that later
but the thing is, if, for instance, you want to
access a USB thumb drive, the USB thumb drive
needs to be mounted to make it accessible, and media
and mnt is where the mounts are happening automatically.
We'll talk about it in more detail later.
opt is an optional directory, not always used.
proc is a very special directory.
This is providing an interface to what the kernel is doing.
We'll talk about it later as well.
root, can we go there?
No, we can't.
And why is that?
Well, that is because this is the home directory
for our root user.
Then we have run.
run is for temporary files.
It's a relatively new addition
to the Filesystem Hierarchy Standard,
and the standard describes that
if a process dynamically creates files,
it can do it in a private environment in the run directory.
Next, there is srv.
srv is for services, not used by default.
There is sys.
sys for managing hardware, a pretty advanced directory.
You have no business going there if you are new to Linux.
We have tmp, which is for your temporary files,
one of the few directories that is writeable by anybody.
We have usr.
usr is so important that we should have a look at it.
In usr, you find a hierarchy for your bin, your binaries,
your sbin, your program binaries, your libraries
and there is usr/local.
Hey, now I'm just wondering, man hier, do we find anything
about /usr/local in man hier?
And there we go.
It's telling us this is where programs, which are local
to the site typically go.
And you know what that means?
This is an important one.
If you are writing a script or anything and you
want to provide it on the system, you should copy it
to usr/local and preferably to usr/local/bin
because the script will be considered a binary,
and binaries need to be in usr/local/bin
Last but not least, there's the var directory.
var is for stuff that is created dynamically,
with one of the most commonly known directories in var,
the var/log directory.
That is where your logging service might write files.
And I say might write files
because nowadays, there is a systemd-journald, and because
of systemd-journald, you may find an empty directory here,
but that's also a topic that we will talk about later.