Shelf of books moving left to right symbolizing the files and directories within the Linux terminal and the Linux directory structure.

Linux Directory Structure Explained – /bin, /etc, /usr

Hey There! Welcome!

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!

The Linux Directory Structure:

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.”

The /bin Directory: The tool Shed

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?

Why do these files seem to be playing hide and seek with their extensions?

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.

  • Blue signifies directories.

  • Green is for executables.

  • White is for text files.

  • And various other colors for different system files that we’ll explore in future lessons.

With that in mind, we can deduce that the bin directory is mostly filled with executable files. How cool is that?

The /etc Directory: Not just "Etcetera"

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.

The /Usr Directory: The User's Universe

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.

Other Noteworthy Linux Directories:

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:~$ 

				
			
  • First up is the /media directory, which contains directories that represent removable media devices.

    You know how when you plug in a USB drive in a Windows system, a new directory appears for you to click on? In Linux, this is where that directory pops up! By navigating here, we can access all the removable media we’ve plugged into our computer.

  • Another directory that might have drawn your attention is a directory called 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)

    Why is it not located within the /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.

  • The remaining directories here mostly contain various types of system files, which we’ll explore throughout this course. So, for now, don’t worry about them.

Final Thoughts:

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.

Fun Facts to brighten your day:

  • 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!

Test Your Knowledge (Practice Quiz):

There has been error loading this quiz, please refresh the page or enable JavaScript to continue.

0/5

Take your Knowledge to the next level!

Learn the Linux command line with our interactive course!

Welcome back!

Don't have an account? Select the register button to create one!

First time around?

You're in the right place! Fill out the form to create your account: