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.
File hierarchy in the form of treesThe 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
- How to send backup copies of Raspberry Pi files to email
- 3 ways to edit file boot / config.txt on Raspberry Pi
- 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
- How to install Android on a Raspberry Pi
- How to start Raspberry Pi 3 from USB