How To Navigate & Use the Linux Directory Structure
It can be very confusing for new users
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 asslash. 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 asroot, lib, andboot. These are examples of Linux distribution directories.
Linux systems use aFilesystem 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 thels(list storage) command and pressEnter. 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:
ls /
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.
ls /home
To clear the screen, typeclearor usectrl L. Keep in mind thatctrl Lmight not work on all Linux distributions, but theclearcommand will.
Let’s go back to thelscommand. 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 tols. For example, typingls -l/displays a different output thanjust/. 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-lcommand 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 usellas an alias for-lfor 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 is by default where all users have their own personal working space. Each user will have their own folder in the/homedirectory.
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 uselsto 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,lswithout 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:
cd /
If you want to see the directories in the root, use:
ls
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:
ls -l
All directories and files on your system reside in therootfile 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:
Root/home/user/videos
The root directory is for a single user and is the most powerful user on a Linux system.
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.
The media directory is where you can see the data files of mounted external hard drives, thumb drives, DVDs, or Blu-ray disks.
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:
Read Wikipedia’s summaryfor 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 commandpwd(print working directory).
The results will look like this:
/home/username
If you then runls, 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/etcfolder 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:
The colors may vary by distribution. Most, but not all, distros come with pre-set colors.
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. Thedmeans directory. So, even if your Linux distro doesn’t use different colors, you will still know that a character string that begins withdis a directory.
Files and programs start with a hyphen (-).
Anlrefers to a link that links to another file.
Quick Navigation Overview
Thelscommand list storage shows you what is in your current working directory. If you don’t know what your current directory is, use thepwdcommand.
The beginning of the file system is designated by a single forward-slash (/). Use thecdcommand to switch between directories. To see what’s in the directory you just switched to, use thelscommand. Then, to go back to your home directory, type/home/username.
Thecdcommand helps you navigate the file system.lsshows you what is in the current directory where you are working.ls -1shows 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 thecd,ls, andpwdcommands 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.
David has a background in small business and lives in Australia. He is a WordPress and Ubuntu Developer who enjoys design, CSS and tech tool integration.Read David’s Full Bio
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved