The Linux file system is very specific and, for new Raspberry Pi users, can be hard to understand. Where are my files? Why are there so many folders and subfolders? The goal of this article is to give you an overview of the file system on a Raspberry Pi (and on any Linux device).
The Linux file system can be seen as a tree. The / location is the root, where the trunk begins. Each sub-folder is a big branch (/home, /var, /etc, …), and these branches also have smaller branches (/home/pi, /var/www, /var/lib, …).
We will start with a general overview of the Linux file system (the tree), list the most useful folders to know, and then review common mistakes in the file system usage. This post idea comes from a survey I distributed in my emails, so I hope it will at least help the person who asked for it.
If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.
The Raspberry Pi File System
The Linux File system
The first thing to understand is that the Raspberry Pi doesn’t use a specific file system tree, it’s a standard from the Linux Foundation named “Filesystem Hierarchy Standard” or FHS. So, you’ll find the same hierarchy on any Linux distribution.
For those interested in this, you can find all the information about this standard in the official documentation here.
The Linux tree
I introduced this concept at the beginning of the article, but I want to illustrate it here because it’s important. Most common mistakes come from a misunderstanding at this point (we’ll discuss them later).
So, as I told you, you can see the file hierarchy as a tree, with “/” as the root folder, and each subfolder as a new branch. In this picture, I presented it more like an organizational chart, but you can revert it if you don’t understand the tree analogy.
Colored cells are folders, and white are files.
At the top, there is the root folder: /. Then home and etc are subfolders, two big branches (there are other ones). pi and user2 are subfolders from home, passwd and hosts are two files in etc.
The file location is identified as /etc/passwd for example.
So, / and etc because they are the folders where you can find the file, and then you add another / for each subfolder and the file name at the end.
Another example: /home/pi/Documents/MyDoc.doc. You have to go through /, home, pi and Documents to find it from the root folder.
I hope that this notation is clearer now.
File system format
I also often see this question about the file format used by Raspberry Pi OS, but I don’t think it’s relevant. In fact, the Raspberry Pi Foundation uses a boot partition in a FAT format (good news for people on Windows because you can read and write on it), and a Linux format for the main partition (probably EXT4).
That’s it, you have the information, but you can’t do anything with it, as the format is included in the image file and you can’t control it.
Most useful folders to know
Home is the short version of “home directories”.
It contains one subfolder per user (for example: /home/pi).
Each user directory contains personal data, like preferences, documents, downloaded files etc.
On Raspberry Pi OS Desktop, you’ll get many subfolders by default in /home/pi:
It’s close to Windows on this point.
Note: I keep /home/pi as the example for this article, as the default user home folder. But you may already know that it’s no longer the case on recent versions of Raspberry Pi OS. In your system, it’s probably another name, like /home/pat, if “pat” is the username you created during the first boot.
/root is the same thing as /home for the administrator user.
Basically, we don’t use it on Raspberry Pi.
But, if you log in as root, you’ll go to this folder as your home folder.
Etc contains all the configuration files.
There are several explanations given for the name, but the one I prefer is “Editable Text Configuration”.
There are a few files directly available in /etc, for example:
- /etc/resolv.conf: If you want to change your DNS server.
- /etc/crontab: For task scheduling (more detail here).
- /etc/sudoers: To manage users with the sudo permission.
And for more complex configurations where there are several configuration files, you’ll more frequently find a specific subfolder for them:
- /etc/apache2: If you use apache as a web server, this folder contains all the configuration files.
- /etc/ssh: same thing for SSH client and server.
- /etc/php: same thing for PHP,
You understand the concept, if you are looking for a configuration file, it’s probably somewhere under /etc.
Var is the abbreviation of “Variable files”.
It means files that are modified during a program execution (log files for example).
Here are the most common subfolders you need to know:
- /var/log: contains all the system log files.
- /var/www: will be used as soon as you install a web server, it’s the root folder for the web server (public files need to be in /var/www/html).
- /var/lib/mysql: the same thing for a MySQL server, it contains all database files. Generally, other database engines also have their files somewhere in /var/lib.
- /var/mail: mailboxes files.
/usr mainly contains application files you don’t need to touch (like binaries and libraries).
I generally use /usr/local/bin as the main folder for my scripts because I learned like this, but I don’t know if it’s a good practice. Saving your scripts in a folder like /home/pi/scripts is probably a better idea.
/bin is something similar for essential command binaries.
There is no subfolder in this one, just binaries like ping, cp/mv/rm or nano.
It’s the only available binaries when you boot in single-user mode; any user can use them.
I didn’t find opt in the standard description, but I often use it, so I added it here.
/opt is the abbreviation of optional, and it’s mainly used for optional application packages.
When I use it, it’s generally for applications that I download on GitHub, not from the Raspberry Pi OS repositories. For example, if you install AlexaPi on your Raspberry Pi, the documentation tells you to download the files here, and then you use the binary file from /opt/AlexaPi.
/media and /mnt
/media and /mnt are not mandatory, but you’ll probably use them when you use USB drives.
In theory, /mnt is for temporary mounted file systems and /media for removable media.
So if you mount a USB drive, you’ll create a folder like /media/usb and mount it in this folder.
Tips and Common Mistakes
This part is a list of tips coming from the mistakes I often see with the Linux file system. In my job, I train new employees on Linux usage, and I always see the same errors.
By the way, I wrote an entire book about Linux, and Linux commands in particular. If that’s the kind of thing you struggle with, it might be worth taking the time to read it. You can find all the details here.
Know where you are
Most tips can be avoided if you have a clear idea of where you are in the Linux files tree.
In general, the current path is written in the Terminal prompt:
In this screenshot, you have the current user, the device name and the current path: /var/log/apt.
If you don’t have it, you can use the following command to find it:
No, it’s not the abbreviation of “password” but “print working directory”.
It’s critical to know where you are when you use a command.
For example, if you use:
sudo rm -rf * to remove all files at your location, it’s better to be sure where you are because a wrong location will probably destroy your system.
So, let’s say you are in /var/log/apt and want to go to your home folder.
You have several options, that all work:
Obviously, the last one is better, but all of them work.
The most common mistake is not knowing when to use /home/pi or home/pi for example.
You can omit the first slash only if you already are in the top folder.
If you are in /home, you can use:
If you are in /, you can use:
But most of the time, it’s difficult to understand.
In general, I recommend always using the first /, even if there is a shorter version possible, it’s easier to understand in the beginning.
For example, if you are in /home/pi,
cd Downloads and
cd /home/pi/Downloads work, but
cd /Downloads doesn’t work, there are no folder Downloads in the root directory (/).
If you understand directly, perfect, if not, keep the long version, it’s better than trying things for 10 minutes each time you use
Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips.
Execute a script
This one is almost the same problem.
When you execute a script, you need to indicate the path.
In general, something like:
But if you don’t want to use the first command, and run the script directly (in a crontab for example), which path do you use if you are in /home/pi?
Yes, 1, 2 and 4 work, but not the other one.
It’s the same thing for anything you want to do with files.
You need to use either the relative path or the absolute path (full path from the root), but not a mix of both.
Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.
That’s it, you now know a bit more about how the Linux file system works.
I hope you liked this post, and will remember a few things after that.
As usual, this kind of learning takes practice to be memorized in the long term.
So, don’t stop here, use Raspberry Pi OS Lite or a terminal more often, and understand your mistakes or why you are using these commands. Is there a shorter method to do the same thing (with the absolute path, for example)?
If you need help with the terminal usage, here are a few posts that should help:
Whenever you’re ready, here are other ways I can help you:
The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.
You can also find all my recommendations for tools and hardware on this page.