Linux directory systems are different from Windows and can be confusing for new users. So think of the Linux directory structure as a tree. The root of a tree is where it grows from, and on Linux, this is where directories fork.
The directory separator is the forward slash (/), which is abbreviated as forward slash. For example, the path to the root directory is often indicated by a forward slash (/).
What is the Linux directory structure?
Those familiar with Linux have heard terms like root, lib, and boot. These are examples of Linux distribution directories.
Linux systems use the File System Hierarchy Standard (FHS). It defines the contents and directory structure of all Linux distributions.
Basic navigation
As mentioned above, the Linux directory structure refers to the folder on the hard drive where Linux was installed.
Start by running ls (list of repositories) and press Enter. This command will show you a list of folders in your current working directory.
– /
Remember, each distribution has different folders in its home directory.
The list command is used to store a list, but the filesystem starts with a single forward slash (/), so enter the following command:
ls /
This will show you the Linux file system directory structure, hard drive settings or default folder structure.
Each folder has its own purpose. The home directory contains users, so use the following command to find out what is in your user’s home directory.
ls / home
To clear the screen, enter clear or use ctrl L. Note that ctrl L may not work on all Linux distributions, but the clear command will.
Let’s go back to the ls command. This is the most important command to know and understand. You want to list items in the directory you are in.
But you can also add additional commands to ls. For example, typing ls -l / will output something other than just /. Try it with the following command:
ls -l /
You can see a lot more information on the screen. Everyone is basically on their own line. The -l command means search for a long list.
This means you want to see more detail and also highlight each element 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
There are many folders on your Linux system. Below we will discuss the most important ones.
Home Directory
The default home directory is where all users have their personal workspace. Each user will have their own folder in the / home directory.
If you want to see a list of all folders in your home directory, use the following command:
ls -l / home
Since you’re already in your home directory, you can also just use ls to open a list of what’s inside, without using the path.
Each 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 return to the root of the filesystem, use the following command:
cd /
If you want to see directories at the root use:
ls
Since you are back in the root directory and not your home directory, you will see a list of all folders in the root.
To see a long list in the root directory use:
ls -l
Root directory (/ root)
All directories and files on your system are located in the root file denoted by the / symbol. All files or directories start at the root. The path to any file or directory will be displayed like this:
Root / home / user / video
The root directory is for one user and is the most powerful user on a Linux system.
Shared Libraries (/ lib)
The / lib directory contains files containing code (libraries). These files contain pieces of code used to send files to the hard drive, draw windows on the desktop, or control peripheral devices.
Media directory (/ media)
The media directory is where you can see the data files of the connected external hard drives, flash drives, DVDs or Blu-ray discs.
Boot directory (/ boot)
The files and folders required to start your system are located in the / boot directory. Its use is standardized in the Filesystem Hierarchy Standard
The configuration required to boot your machine is located 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 are located, such as an external USB drive or webcam.
- / var is short for variable. This is where programs store runtime information such as user tracking, system logs, caches, and other files that system programs manage and create.
- Users’ personal directories are located in / home.
- / proc contains information about your system, such as the processor and kernel of your Linux system. It is a virtual system.
- / bin is where all the main executable programs (custom binaries) reside.
- The / etc folder contains configuration files.
- Blue is a folder
- White is a file
- Green is a program or binary
Read the Wikipedia summary to find out what each directory is and how it is used.
Check your current directory
If you don’t know which directory you are working in, use the pwd (print working directory) command.
The result will look like this:
/ home / username
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 execute this command:
ls -l / etc.
You will see a lot of information as well as many different colors.
A general rule of thumb is this:
Colors may vary depending on distribution. Most, but not all, distributions come with pre-installed colors.
What are permission strings?
To the left of the list of each file is a stream of letters. This is called a permission string.
Look at the first character on the line. The letter d stands for directory. This way, even if your Linux distribution does not use different colors, you will still know that the character string starting with d is a directory.
Files and programs start with a hyphen (-).
The letter l refers to a link to another file.
Quick Navigation Overview
The ls command list store shows what is in your current working directory. If you don’t know what directory your current directory is in, use the pwd command.
The beginning of the filesystem is indicated by a single forward slash (/). Use the cd command to switch between directories. To see what’s in the directory you just changed to, use the ls command. Then, to return to your home directory, enter / home / username.
The cd command helps you navigate the file system. ls shows you what’s in the current directory you’re working in. ls -1 shows a long list.
Although there are minor differences between different Linux distributions, the file system layouts are very similar. The best way to understand the Linux directory structure is to follow some of the suggestions above and become familiar with how it works.
Just don’t touch the / boot directory. Practice navigating your system using the terminal. Stick to the cd, ls and pwd commands to avoid breaking anything. It won’t take you long to intuitively figure out where to find documentation, applications, and other resources you need to use.
–