Welcome to our next lesson! Today, we will embark on a tour of the Linux directory structure. We’ll uncover its organization and snoop around various directories. Let’s get started!
As you may recall from our previous lesson, we briefly mentioned that our system’s files are neatly tucked away into different directories, each serving a specific purpose or function.
To gain a deeper understanding of the Linux directory structure, let’s delve into our systems directories and uncover their secrets. Let’s kick off our journey by taking a look at the contents of our root directory.
Rather than navigating there, we can simply instruct the ls
command to display its contents by providing its path as an argument, which as you might recall is represented by a single slash.
ubuntu@ip-172-31-45-72:~$ ls /
bin dev home lib32 libx32 media opt root sbin srv sys usr
boot etc lib lib64 lost+found mnt proc run snap swapfile tmp var
ubuntu@ip-172-31-45-72:~$
We’ve already learned all about the home
directory in a previous lesson, so let’s not dwell on the past. Instead, let’s shine the spotlight on the bin
directory, which stands for “binary.”
No, it’s not a place to store recyclables; the name refers to the specific types of files this directory stores, which are known as binary files. These files are meant to be run as programs, similar to .exe
files in a Windows system.
They are called “binary” because the data they contain consists of ones and zeros, as opposed to other data types, such as text.
So, let’s take a peek inside this directory using our trusty ls
command.
ubuntu@ip-172-31-45-72:~$ ls /bin
apport-cli objcopy
apport-collect objdump
apport-unpack od
apropos oem-getlogs
apt on_ac_power
apt-add-repository open
...
bzfgrep ps
...
ubuntu@ip-172-31-45-72:~$
Wow, that’s a lot of files! Some names may ring a bell, like the ps
file we can see here. But hold on—why do these files share their names with commands?
As we discovered in our previous lesson, commands are essentially small applications. So, when we run the ps
command in our terminal, it is this very file that springs into action, much like double-clicking a .exe
file in a Windows system. Pretty cool, right?
Well, Linux users are a savvy bunch, and they’re expected to know the type of data a file contains and use the appropriate commands or applications to handle them accordingly.
For example, they’d use a text editor to open a text file, rather than double-clicking on it and letting the system decide which application should be used to open it.
To aid with this, some Linux files occasionally do have extensions, but only for informational purposes and user convenience. These extensions don’t perform any other functions; they are simply considered part of a file’s name.
But what about files that don’t have any extensions? How are we supposed to know what data they contain?
Fear not! The file
command comes to our rescue! This command can be used to determine the type of data a file contains. Let’s put it to the test! All we need to do is type the file
command, followed by the path of our file.
For this example, let’s use the ps
file we looked at earlier. Since this file is located within the /bin
directory, which is in turn situated within our root, its absolute path is simply a slash to represent the root directory, followed by the bin
directory, another slash, and the name of our file. Let’s give it a go:
ubuntu@ip-172-31-45-72:~$ file /bin/ps
/bin/ps: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=9ff9402856fe97313644b471f550370ff8e67caf, for GNU/Linux 3.2.0, stripped
ubuntu@ip-172-31-45-72:~$
Don’t sweat it if most of this looks like ancient hieroglyphics; you’re not meant to decipher it unless you’re a specialized Linux programmer. What interests us are the first few words, which indicate that this file is indeed an executable. In a similar way, we can use the file
command to identify the type of any file.
But wait, there’s more! In addition to using the file
command, a quicker way of identifying the type of data a file contains is by observing the colors from the output of the ls
command.
With that in mind, we can deduce that the bin
directory is mostly filled with executable files. How cool is that?
Now that we know all about the /bin
directory let’s continue exploring the Linux directory structure. Starting with the /etc
directory, which is short for “et cetera.” You know the drill – let’s use the ls
command to take a peek within it.
ubuntu@ip-172-31-45-72:~$ ls /etc
Muttrc init.d php
Muttrc.d initramfs-tools phpmyadmin
NetworkManager inputrc pm
...
gshadow- nginx update-notifier
gss nsswitch.conf usb_modeswitch.conf
hdparm.conf opt usb_modeswitch.d
hibagent-config.cfg os-release vim
hibinit-config.cfg overlayroot.conf vmware-tools
host.conf overlayroot.local.conf vtrgb
hostname pam.conf wgetrc
hosts pam.d xattr.conf
hosts.allow passwd xdg
hosts.deny passwd- zsh_command_not_found
init perl
ubuntu@ip-172-31-45-72:~$
This directory primarily contains files that store settings for various system components or hold other essential information.
Files containing settings are called configuration files and are typically denoted by the .conf
extension. By fine-tuning these configuration files, we can dictate how the various components of our system function.
There’s a good chance you’ll find yourself wandering through this directory at some point or another, looking to edit one of those files or view their contents.
But remember, with great power comes great responsibility, don’t mess with these files unless you know what you’re doing! Thankfully, we haven’t learned how to edit files just yet.
Onward to another directory in the Linux directory structure you’ll likely encounter throughout your journey with Linux: the /usr
directory, which is short for “user.” As always, let’s use the ls
command to check it out.
ubuntu@ip-172-31-45-72:~$ ls /usr
bin include lib32 libexec local share
games lib lib64 libx32 sbin src
ubuntu@ip-172-31-45-72:~$
This directory has a lot in common with its cousin, the /bin
directory, as it also stores various executable files.
The key difference is that while /bin
houses only the most essential binaries, this directory stores executables for a wide range of applications. Specifically, binaries are stored in the bin
subdirectory we see here.
The /usr
directory also houses various resources needed for our software to function, hidden away within the rest of these subdirectories. Don’t worry about these just yet—we’ll dive deeper into them when we learn how to install applications.
While it’s unlikely that you’ll need to interact with the rest of these directories, let’s give them a quick hello with the ls
command.
ubuntu@ip-172-31-45-72:~$ ls /
bin dev home lib32 libx32 media opt root sbin srv sys usr
boot etc lib lib64 lost+found mnt proc run snap swapfile tmp var
ubuntu@ip-172-31-45-72:~$
/media
directory, which contains directories that represent removable media devices.root
. This directory, not to be confused with the root directory we’re currently examining, is the home directory for a special type of user account called the “root user.” (More on this here)/home
directory? Well, since the root user is kind of a big deal, having their directory separated helps ensure its isolation and security. But let’s not get ahead of ourselves—we’ll dive into this mysterious user in a future lesson.One key takeaway we want to stress is that memorizing all this information isn’t the goal. Instead, we want you to grasp the purpose of these directories.
As you continue to interact with the command line, you’ll find that understanding these concepts becomes second nature.
Why was the computer cold in the /etc
directory? It left its Windows open! Luckily, it found some nice .conf(y) blankets.
The /bin
directory might sound like a place to toss your digital recyclables, but nope! It stands for “binary,” housing executable files. Think of it as the toolbox where Linux keeps its handy programs, not yesterday’s news.
The /usr
directory, short for “user,” is like the multi-talented cousin of /bin
. It holds not just more binaries but also a buffet of software resources. Think of it as the Swiss Army knife in the Linux toolbox.
In the world of Linux, file extensions play a game of hide-and-seek. They’re there for a peek-a-boo moment but not for functionality. Remember, Linux users are expected to be like detectives, identifying file types without the clues of extensions. Sherlock Holmes would be proud!
Colors in the terminal are not just to make it look pretty. They’re like a secret language, telling you whether a file is executable, a directory, or just a plain text file. It’s like having a color-coded guide to the file system!
Learn the Linux command line with our interactive course!
Don't have an account? Select the register button to create one!
You're in the right place! Fill out the form to create your account: