How does the Raspberry Pi file system work?
The Linux file system is very specific and can be confusing to the new user of the system. Where are your files? Why are there so many folders and subfolders?
The goal of today's article is to give you an overview of the file system on your Raspberry Pi (as well as on any Linux device).
Raspberry Pi file system
Linux file system
The first thing to understand is that the Raspberry Pi does not use a specific file system tree, it is a standard from the Linux Foundation called ' Filesystem Hierarchy Standard ' or FHS.
So you will basically find the same hierarchy on any Linux distribution.
For those interested in this, you can find all of the information in the article: Understanding file and directory systems on Linux operating systems.
Linux tree
Most of the common mistakes come from misunderstandings. So, as said before, you can view the file hierarchy as a tree, with / as the root directory and each subdirectory as a new branch.
In this figure, I have shown it more like an organization chart.

The colored boxes are directories and the white is the file. At the top there is the root directory: /.
Then, home and etc are subdirectories, the two big branches pi and user2 are subdirectories from home , and the passwd and hosts are the two files in etc.
For example, the file location is specified as / etc / passwd. Since / and etc are directories where you can find files, you can add / for each subdirectory and filename 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 directory.
File system format
Actually, Raspberry Pi Foundation uses the boot partition in FAT format (good news for Windows users, as you can read and write on it) and Linux format for primary partition (possibly EXT4) .
You have the information, but nothing can be done with it, because the format is included in the image file and you cannot control it.
The most useful directories to know
/ home
Home is a short version of "home directories". It contains a subdirectory for each user (eg / home / pi ).
Each user folder contains personal data, like preferences, documents, downloaded files, etc.
On Raspberry Pi OS Desktop, you will get many subfolders by default under / home / pi:
- Videos
- Downloads
- Music
- Pictures
- Desktop
At this point, it's actually close to Windows.
/ root
/ root is the same as / home for admin users. Basically, we don't use it on the Raspberry Pi. However, if you are logged in with root privileges, you will go to this directory, as the home directory.
/ etc
Etc contains all the configuration files. There are several possible explanations for this name, but perhaps the Editable Text Configuration is the most appropriate.
There are several files available directly in / etc, for example:
- /etc/resolv.conf: If you want to change DNS server
- / etc / crontab: To schedule a task
- / etc / sudoers: To manage users with sudo privileges
And for more complex configurations, you'll often find a specific subfolder for them:
- / etc / apache2: If you use apache as a web server, this directory contains all the configuration files
- / etc / ssh: same for SSH client and server
- / etc / php: Same thing for PHP
If you're looking for a configuration file, it might be somewhere in / etc.
/ var
Var stands for "Variable files". It means that files are modified during program execution (eg log file).
Here are the most common subfolders you need to know:
- / var / log: Contains all system log files
- / var / www: Will be used as soon as you install the web server, which is the root directory of the web server (public files need to be in / var / www / html ).
- / var / lib / mysql: Same thing for MySQL server, it contains all the database files. In general, other database engines also have their files somewhere in / var / lib.
- / var / mail: File mailbox
/ usr
/ usr mainly contains application files that you do not need to touch (like binaries and libraries). Saving scripts in a directory like / home / pi / scripts is probably a good idea.
/ bin
/ bin is something similar for the required command binaries. There are no subdirectories in this directory, only binaries like ping, cp / mv / rm or nano
In fact, these are the only available binaries when you boot in single-user mode. Any user can use them.
/ opt
/ opt stands for optional and it is mainly used for optional application packages.
For example, if you install AlexaPi on your Raspberry Pi, the documentation guides you to download the files here, then you use the binary from / opt / AlexaPi.
/ media and / mnt
/ media and / mnt are optional but you will probably use them using USB.
In theory, / mnt is for a temporarily mounted file system and / media for removable media. So with USB you will create a directory such as / media / usb and mount it in this directory.
You should read it
- What is the Raspberry Pi and how is the Raspberry Pi used?
- 10 operating systems you can run with Raspberry Pi
- How to install an operating system for Raspberry Pi
- What's New in Raspberry Pi OS 11?
- How to add an ADC to Raspberry Pi: What you need to know
- Raspberry Pi Zero vs Model A and B, how are they different?
- Raspberry Pi OS finally has a 64-bit version
- 8 best lightweight operating systems for Raspberry Pi
May be interested
- How to run the emulator on the Raspberry Pi 4for years, raspberry pi fans have been running game emulation platforms like retropie, recalbox and lakka. however, when the raspberry pi 4 came out, none of these platforms officially supported new hardware, and users had to look for beta versions or alternatives that didn't work very well.
- 8 best lightweight operating systems for Raspberry Pithe operating system for the pi must be compact, so many of the features commonly found in the linux desktop are not required on the raspberry pi.
- Raspberry Pi OS finally has a 64-bit versionthe raspberry pi foundation (rpf) has finally officially announced that the raspberry pi operating system is now available in 64-bit format.
- How to boot Raspberry Pi 4 from USB or over the networkthe raspberry pi is a wonderful, flexible piece of software, capable of a wide range of possibilities, from running a media center to using it as a radio.
- How to install Android on a Raspberry Pialthough there are many operating systems available for the raspberry pi, you may prefer to stick with a linux-based operating system. but what about the lack of touch screen support? perhaps the best solution is to install android on a raspberry pi.
- How to start Raspberry Pi 3 from USBraspberry pi is a great, versatile software suite, with a variety of capabilities like running a media center or using as a radio.
- Why should people try Raspberry Pi 4?the new raspberry pi 4 has been released, but do you need to upgrade? is raspberry pi 4 really offering more features than the previous raspberry pi 3 b +?
- Raspberry Pi AI Kit: Bring AI to Raspberry Pithe raspberry pi ai kit is essentially raspberry pi's new m.2 hat+ board integrated with the hailo-8l acceleration module.
- 9 types of servers that can be hosted on Raspberry Piraspberry pi is a versatile tool. you can use it to light up leds, write work emails, stream movies to old tvs/monitors, or even host game servers.
- Learn Pi Imager, How to Use Raspberry Pi Imagerthe raspberry pi foundation recently released a new application for recording sd cards for the raspberry pi. the new program, called raspberry pi imager, launches march 5, 2020.