banner raspberry pi filesystem tree with folders

How Does the Raspberry Pi File System Work?

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? My goal in 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, the trunk of the tree. Each subfolder is a big branch (/home, /var, /etc, …), and these branches also have smaller branches (/home/pi, /var/www, /var/lib, …).

We’ll start with a general overview of the Linux file system (the tree), discuss the most useful folders to know, and then review common mistakes in file system usage. This post idea comes from a survey I distributed to my email list, 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.

Want the best experience? Become a premium member for ad-free browsing, access exclusive content, and ask questions in our private forums. Your membership helps support the site!

The Raspberry Pi File System

The first thing to understand is that the Raspberry Pi doesn’t use a unique file system tree; it follows a recommended structure from the Linux Foundation called the “Filesystem Hierarchy Standard” or FHS. So, you’ll find this same hierarchy on any Linux distribution.

If you’re interested in learning more about FHS, you can read all about it 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).

As I mentioned, you can see the file hierarchy as a tree, with “/” as the root folder, and each subfolder as a branch. In this diagram below, I’ve presented it more like an organizational chart, but you can invert it to better picture the tree analogy.

The colored-in cells represent folders, while white cells represent files.

At the top, there is the root folder: /. Then /home and /etc are subfolders—in other words, two major big branches (there are others). The “pi” and “user2” subfolders belong to /home, while “passwd” and “hosts” are two files in /etc.

A file’s 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.

Here’s another example: /home/pi/Documents/MyDoc.doc. You have to go through /, home, pi and Documents to get to it from the root directory.

I hope that this notation is clearer now.

File System Format

I 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 it easily), 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.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Useful Folders to Know

Now that you understand that Raspberry Pi OS follows the Linux FHS, you might be wondering what directories are standard on Linux. In this section, I’ll go over the most commonly used ones.

folder icon purple

/home

The /home folder is short for “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, each user will get many subfolders by default:

  • Videos
  • Downloads
  • Music
  • Pictures
  • Desktop
  • Etc.

It’s similar to Windows on this point.

Note: I give /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

The /root folder is the same thing as /home, except it’s reserved 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

The /etc folder contains all the configuration files.
There are several explanations for the name, but the one I prefer is “Editable Text Configuration.

There are a few files directly available in /etc, for example:

And for more complex configurations where there are several configuration files, you’ll more frequently find a specific subfolder for the program or service. For example:

You get the concept: if you’re looking for a configuration file, it’s probably somewhere under /etc.

/var

The /var folder is the abbreviation for “variable files.”
It refers to files that are modified during program execution (log files for example)
.

Here are the most common /var subfolders you need to know:

  • /var/log: contains all the system log files.
  • /var/www: If you install a web server, this folder holds your website’s files (public files need to be in /var/www/html).
  • /var/lib/mysql: This folder contains all database files for a MySQL server. Generally, other database engines also keep their files somewhere in /var/lib.
  • /var/mail: mailboxes files.

/usr

The /usr directory 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 it like this, but I don’t know if it’s good practice. Saving your scripts in your home folder like /home/pat/scripts is probably a better idea.

/bin

The /bin folder is for essential command binaries.
There are no subfolders in this one, just binaries like ping, cp/mv/rm, and nano.
These are the only available binaries when you boot in single-user mode; any user can use them.

/opt

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.

I’ll generally use it for applications that I download from GitHub instead of the official 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 can call the binary from /opt/AlexaPi.

/media and /mnt

The /media and /mnt folders aren’t required, but you’ll probably use them for 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.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Tips and Common Mistakes

This section contains a list of tips that came 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.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now
laptop showing user error

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:
terminal prompt showing path

In this screenshot, you have the current user, the device name and the current path: /var/log/apt

If you don’t see a path, you can use the following command to find it:
pwd
No, it’s not the abbreviation for “password” but for “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, you better be sure where you are—running this command in the wrong location will probably destroy your system.

cd

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:

cd ..
cd ..
cd ..
cd home
cd pat

cd ../../..
cd home/pat

cd /
cd home/pat

cd /home/pat

Obviously, the last example is fastest, but all of them work.

The most common mistake is not knowing when to use /home/pat or home/pat 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: cd pat/Downloads
If you are in /, you can use: cd var/log
But most of the time, it’s difficult to understand.

In general, I recommend always using the first / because even if there’s 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/pat/Downloads work, but cd /Downloads doesn’t work because there’s no Downloads folder in the root directory (/).
If you understand directly, perfect. If not, use the longer version; it’s better than trying things for 10 minutes each time you use cd.

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

Similar to above, this mistake is a syntax error.
When you execute a script, you need to indicate the path.
In general, something like:

cd /home/pat/scripts
./myscript.sh

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’re in the /home/pat directory?

  1. scripts/myscripts.sh?
  2. ./scripts/myscript.sh?
  3. home/pat/myscript.sh?
  4. /home/pat/myscript.sh?

Yes, 1, 2 and 4 work, but not 3 doesn’t.

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.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

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.

Conclusion

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 memorize 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 want more help with 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.

How would you rate this article?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Spread the word!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Similar Posts

2 Comments

  1. I’ve worked with UNIX-like file sysems since the 1980’s and I’ve never before seen the explanations “Editable Text Configuration” or “Variable files” for /etc and /var. Knowing the mnemonic for etc would have saved many typos, Thanks!

  2. I bet you didn’t know that if you use the command cd with no arguments:
    cd
    It usually takes you to your home directory.
    cd ~
    Does the same thing, and can be used as a replacement for the path to the current users home directory like
    cd ~/Documents

Comments are closed.