Linux directory systems are different from Windows and may confuse new users. So think of the Linux directory structure as a tree. The root of the tree is where it grows from and in Linux, it is where the directories branch out.
The directory separator is the forward-slash (/), abbreviated as slash. For example, the path to the root directory is often referred to as slash ( /).
What Is the Linux Directory Structure?
For those who are familiar with Linux, you have heard terms such as root, lib, and boot. These are examples of Linux distribution directories.
Linux systems use a Filesystem Hierarchy Standard (FHS). It defines the content and directory structure of all Linux distributions.
As mentioned above, the Linux Directory structure refers to the folder of the hard drive where Linux was installed.
Start by running the ls (list storage) command and press Enter. This command will show you a list of folders in your current working directory.
Keep in mind that each distribution comes with different folders in the home directory.
The list command stands for list storage, but the file system starts with a single forward-slash (/) so enter the following command:
This will show you the directory structure of the Linux file system, the setup of the hard drive, or the default folder structure.
Each folder has a designated purpose. The home directory is where the users are, so use the following command to see what’s in your user home directory.
To clear the screen, type clear or use ctrl L. Keep in mind that ctrl L might not work on all Linux distributions, but the clear command will.
Let’s go back to the ls command. It is the most important command to know and understand. You want to list the items in a directory where you are located.
But you can also add additional commands to ls. For example, typing ls -l / displays a different output than just /. Try it by using the following command:
ls -l /
You can see a lot more information on the screen. Everything is basically on its own line. The -l command means to look for the long listing.
This means you want to see more details as well as every item to be on a separate line to make it easier to read. Some distributions will use ll as an alias for -l for the long list command.
Important Folders You Should Know About
There are a lot of folders in your Linux system. We will discuss the most important ones below.
The Home Directory
The home directory is by default where all users have their own personal working space. Each user will have their own folder in the /home directory.
If you want to see a listing of all the folders in your home directory, use the following command:
ls -l /home
Because you are already in your home directory, you can also just use ls to pull up a list of what’s inside without using a path.
Every directory in the Linux directory structure is separated by and starts with a forward slash (/). In other words, ls without a path will show the contents of your current directory.
If you want to change the directory you are working in and go back to the root of the file system, use the following command:
If you want to see the directories in the root, use:
Because you are back in the root directory and not your home directory, you will see a list of all the folders in the root.
To see the long list in the root directory, use:
The Root Directory (/root)
All directories and files on your system reside in the root file represented by the symbol /. All files or directories start at the root. The path of any file or directory will be displayed similar to the following:
The root directory is for a single user and is the most powerful user on a Linux system.
Lib Directory Shared libraries (/lib)
The /lib directory is where files containing code (the libraries) are located. These files house the code snippets used to send files to your hard drive, draw windows on your desktop, or control peripherals.
Media Directory (/media)
The media directory is where you can see the data files of mounted external hard drives, thumb drives, DVDs, or Blu-ray disks.
Boot Directory (/boot)
The files and folders your system needs to start are in the /boot directory. Its usage is standardized in the Filesystem Hierarchy Standard.
The configuration needed to boot your machine lives in the boot directory. You don’t want to get rid of this directory.
Some other standard directories include:
- /dev is where all device files live, such as an external USB or a webcam.
- /var is short for variable. It is where programs store runtime information such as user tracking, system logging, caches, and other files that system programs manage and create.
- Users’ personal directories are in /home.
- /proc contains information about your system such as CPU and your Linux system kernel. It is a virtual system.
- /bin is where all the essential runnable programs (user binaries) live.
- /etc folder contains the configuration files.
Read Wikipedia’s summary for a full breakdown of what each directory is and how it is used.
See Your Current Directory
If you don’t know which directory you are working in, use the command pwd (print working directory).
The results will look like this:
If you then run ls, the default setting will show you the contents of the folder you are currently in, as described above.
What Do The Colors Mean?
Let’s say you are in the /etc folder and run this command:
ls -l /etc
You will see a lot of information as well as many different colors.
The general rule of thumb is that the:
- Blue is a folder
- White is a file
- Green is a program or a binary
The colors may vary by distribution. Most, but not all, distros come with pre-set colors.
What Are Permission Strings?
Every file has a stream of letters to the left of the listing. It is called a permission string.
Look at the first character in the string. The d means directory. So, even if your Linux distro doesn’t use different colors, you will still know that a character string that begins with d is a directory.
Files and programs start with a hyphen (-).
An l refers to a link that links to another file.
Quick Navigation Overview
The ls command list storage shows you what is in your current working directory. If you don’t know what your current directory is, use the pwd command.
The beginning of the file system is designated by a single forward-slash (/). Use the cd command to switch between directories. To see what’s in the directory you just switched to, use the ls command. Then, to go back to your home directory, type /home/username.
The cd command helps you navigate the file system. ls shows you what is in the current directory where you are working. ls -1 shows you the long listing.
Even though various Linux distributions have minor differences, the file system layouts are very similar. The best way to understand the Linux directory structure is to follow some of the above suggestions and familiarize yourself with how it works.
Just be sure NOT to touch the /boot directory. Practice navigating through your system using the terminal. Stick to the cd, ls, and pwd commands so that you don’t break anything. It won’t take long for you to intuitively know where to find documentation, apps and other resources you need to use.