Skip to content

Commit 0f802fb

Browse files
committed
unpublished articles
1 parent 4fb4aa9 commit 0f802fb

File tree

6 files changed

+218
-3
lines changed

6 files changed

+218
-3
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

_posts/XXXX-XX-XX-linux-tree.md

Lines changed: 218 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,227 @@ color: success
66
description: Briefly analyzing Linux tree structure
77
---
88

9+
![linux](../assets/blog_images/XXXX-XX-XX-linux-tree/linux.png)
10+
911
# Introduction
1012

11-
A
13+
I usually find myself having a drink with friends, and a question arises: why would someone want to use Linux? It seems like a reasonable doubt; OSs like Windows are easier to use, have a showcase (UX) that is, at first glance, prettier, you can play more games on them immediately, it does not require computer knowledge to use, everything that a common person needs comes pre-installed, and it has many default tools, it has great support, etc. Moreover, it has the Windows Subsystem for Linux (WSL)!, which is essentially a compatibility layer from Microsoft to run Linux binaries (even using a real Linux kernel) within Windows itself (although obviously more limited than a native one).
14+
15+
But if you are a programmer, you will understand that once you overcome the (not so flat) learning curve of Linux, the flexibility and control it offers will allow you to do things that in other operating systems you would find more limited. And perhaps more relevant, with the certainty that the OS is user- and privacy-respecting; you will be able to use your OS as you prefer. Linux does not operate under a proprietary software policy with forced updates and advertisements; moreover, it advocates much more for open software, which is especially interesting if you are a developer or researcher. It is easier to learn (out of curiosity) computer concepts in Linux than in Windows; and also to program and develop, let’s not fool ourselves. If your machine is very old, it probably cannot run an arbitrary Windows or MacOS, but it can run Linux. Also, if you are a computational artist and you like to customize your GUI or desktop _to the maximum_, Linux offers you more possibilities than any other.
16+
17+
On the other hand, security (let's think about this in a very loosely strict way): the vast majority of users use Windows; so it is logical that the vast majority of cyberattacks are directed at Windows distributions; it is not that we are safer in Linux, which we are, but that we most probably are. Although under this same thinking, it is more frequent to have drivers/hardware support for Windows and not for Linux.
18+
19+
But enough talking about competitions, since each option meets different needs, and they are not mutually exclusive. We will dedicate this post to delving into the Linux directory tree (and other UNIX-like operating systems). For Windows users, the well-known `C:\` drive and drive letters no longer exist; instead, the entire structure is replaced by a labyrinthine hierarchical file system and directories governed by the Filesystem Hierarchy Standard (FHS), which is the standard maintained by the Linux Foundation.
20+
21+
# The Linux structure
22+
23+
Before anything else, let's take a look and appreciate this beautiful tree of Linux distributions (GNU/Linux):
24+
![distros](../assets/blog_images/XXXX-XX-XX-linux-tree/distros.png)
25+
26+
This is my system:
27+
```bash
28+
$ uname -a
29+
```
30+
```text
31+
Linux pop-os 6.9.3-76060903-generic #202405300957~1732141768~22.04~f2697e1 SMP PREEMPT_DYNAMIC Wed N x86_64 x86_64 x86_64 GNU/Linux
32+
```
33+
34+
Linux is an OS that works like a "big file system", or rather, "through files". Everything we see, even the directories themselves, the mouse, keyboard, printer..., are files. How can that be? It’s not that far-fetched; in the eyes of a computer, its lifeblood is 0s and 1s, and files contain nothing but binary numbers.
35+
36+
There are several types of files in a Linux system:
37+
38+
1. **General/Ordinary/Regular Files**: It may be an image, video, program, text file, or executable. These types of files can be in ASCII or binary format. It is the most commonly used file type in the Linux system.
39+
40+
2. **Directory Files**: These types of files are a storage for other file types, so there may be a directory file within a directory (subdirectory).
41+
42+
3. **Device Files**: In a Windows-like operating system, devices like CD-ROMs and hard drives are represented as drive letters like F:, G:, H:, whereas in the Linux system, devices are represented as files. For example, `/dev/sda1`, `/dev/sda2`, and so on. These comprise symbolic links, block files, socket files, and named pipe files.
43+
44+
We are at the top of the Matrix (root), and we look below and identify 23 distinct directories. Most Windows people keep their whole lives warm inside the `/home` directory. But we are **gente con intriga**, and we will try to understand why each of them exists. We will go in a _certain_ order...
45+
46+
## root (/) - Root Directory
47+
48+
The Linux filesystem hierarchy starts with the root directory as its foundation. It contains all other directories and subdirectories.
49+
50+
Let's take a look at the inmediate response of what we see below here:
51+
52+
```bash
53+
alejandro@pop-os:/$ tree -D -L 1
54+
[Dec 18 14:20] .
55+
├── [Sep 18 18:35] bin -> usr/bin
56+
├── [Jan 21 13:26] boot
57+
├── [Feb 1 11:16] dev
58+
├── [Jan 30 11:38] etc
59+
├── [Dec 18 14:18] home
60+
├── [Sep 18 18:35] lib -> usr/lib
61+
├── [Sep 18 18:35] lib32 -> usr/lib32
62+
├── [Sep 18 18:35] lib64 -> usr/lib64
63+
├── [Sep 18 18:35] libx32 -> usr/libx32
64+
├── [Dec 18 14:05] lost+found
65+
├── [Dec 18 14:42] media
66+
├── [Sep 18 18:35] mnt
67+
├── [Jan 31 13:48] opt
68+
├── [Feb 1 11:15] proc
69+
├── [Jan 1 1970] recovery
70+
├── [Jan 18 12:39] root
71+
├── [Feb 1 11:16] run
72+
├── [Sep 18 18:35] sbin -> usr/sbin
73+
├── [Sep 18 18:35] srv
74+
├── [Feb 1 11:15] sys
75+
├── [Feb 1 11:59] tmp
76+
├── [Sep 18 18:35] usr
77+
└── [Dec 17 07:26] var
78+
79+
23 directories, 0 files
80+
```
81+
82+
## /bin - Essential Binaries
83+
84+
This directory stores essential executable programs for all users, such as `ls`, `cp`, `mkdir`, `rm`, among others.
85+
86+
## /boot - Boot Files
87+
88+
Contains files needed for the system to boot, including the Linux kernel (`vmlinuz`), the bootloader (`grub`), and other essential boot configuration files.
89+
90+
## /dev - Device Files
91+
92+
Contains special files representing system devices, such as hard drives (`/dev/sda`), terminals (`/dev/tty`), and other peripherals.
93+
94+
## /etc - Configuration Files
95+
96+
Stores system and application configuration files. Examples include:
97+
98+
- `/etc/passwd`: User account information.
99+
- `/etc/group`: Information about user groups.
100+
- `/etc/fstab`: File system and mount point information.
101+
102+
## /home - User Directories
103+
104+
Each user has a personal directory under `/home` to store their files and configurations. Example: `/home/username`.
105+
106+
```bash
107+
alejandro@pop-os:/home$ tree -D -L 2
108+
[Dec 18 14:18] .
109+
└── [Feb 1 11:16] alejandro
110+
├── [Jan 24 18:05] Desktop
111+
├── [Jan 21 19:16] Documents
112+
├── [Jan 29 01:04] Downloads
113+
├── [Jan 22 13:04] gems
114+
├── [Dec 18 14:29] Music
115+
├── [Jan 23 22:00] Pictures
116+
├── [Dec 18 14:29] Public
117+
├── [Dec 18 14:29] Templates
118+
└── [Jan 21 19:17] Videos
119+
120+
10 directories, 0 files
121+
```
122+
123+
## /lib - Shared Libraries
124+
125+
Holds essential libraries required to run the binaries in `/bin` and `/sbin`. These libraries are critical for both the operating system and the applications in those directories.
126+
127+
## /lib32- Shared Libraries
128+
129+
Contains 32-bit libraries for running 32-bit applications on 64-bit systems.
130+
131+
## /lib64- Shared Libraries
132+
133+
Stores 64-bit libraries needed to run 64-bit applications on 64-bit systems.
134+
135+
## /libx32- Shared Libraries
136+
137+
Contains shared libraries for the x32 architecture, which uses 32-bit pointers but operates in 64-bit mode.
138+
139+
## /lost+found - File Recovery
140+
141+
Used to store fragments of files recovered after file system failures.
142+
143+
## /media - Removable Media Devices
144+
145+
Mounts removable devices like USB drives, CD-ROMs, and external disks.
146+
147+
## /mnt - Temporary Mount Points
148+
149+
Temporary mount point for external file systems, such as additional hard drives or partitions.
150+
151+
## /opt - Optional Software
152+
153+
Contains manually installed software and third-party applications, typically those not included in the default package management system.
154+
155+
## /proc - Virtual File System
156+
157+
A pseudo-filesystem that stores information about running processes and system state. Examples:
158+
159+
- `/proc/cpuinfo`: Processor information.
160+
- `/proc/meminfo`: Memory usage statistics.
161+
- `/proc/filesystems`: Supported file systems.
162+
163+
## /recovery - Systen Recovery
164+
165+
Used in some distributions to store recovery tools and files in case of system failures.
166+
167+
## /root - Root User Directory
168+
169+
The personal directory of the root user (administrator), similar to `/home`, but exclusive to the superuser.
170+
171+
## /run - Volatile Runtime Data
172+
173+
Contains data files used by running processes. It is cleared upon reboot.
174+
175+
## /sbin - System Binaries
176+
177+
Stores system binaries, including administrative commands for the superuser, such as `fdisk`, `fsck`, `reboot`, and `shutdown`.
178+
179+
## /srv - Service Data
180+
181+
Contains data used by services like web servers, FTP servers, and databases.
182+
183+
## /sys - System and Hardware Information
184+
185+
A virtual file system that stores information about hardware devices and kernel configurations.
186+
187+
## /tmp - Temporary Files
188+
189+
Stores temporary files that can be deleted after use. It is generally cleared upon reboot, so it's not suitable for important data.
190+
191+
## /usr - User Programs and Data
192+
193+
Contains installed programs and applications, along with shared data such as libraries and documentation. Key subdirectories:
194+
195+
- `/usr/bin`: User binaries.
196+
- `/usr/sbin`: Administrative binaries.
197+
- `/usr/lib`: Shared libraries.
198+
- `/usr/share`: Shared files like documentation and themes.
199+
- `/usr/local`: Manually installed software.
200+
201+
```bash
202+
alejandro@pop-os:/usr$ tree -D -L 1
203+
[Sep 18 18:35] .
204+
├── [Jan 30 11:38] bin
205+
├── [Apr 18 2022] games
206+
├── [Jan 18 12:49] include
207+
├── [Jan 29 12:03] lib
208+
├── [Sep 18 18:35] lib32
209+
├── [Dec 17 07:01] lib64
210+
├── [Jan 3 13:07] libexec
211+
├── [Sep 18 18:35] libx32
212+
├── [Jan 12 22:17] local
213+
├── [Jan 30 11:38] sbin
214+
├── [Jan 30 11:38] share
215+
└── [Jan 21 13:20] src
216+
217+
12 directories, 0 files
218+
```
219+
220+
## /var - Variable Data
221+
222+
Contains files whose content changes frequently, such as logs, mail, and spool files. Examples include:
12223

13-
# References
224+
- `/var/log`: System log files.
225+
- `/var/cache`: Program cache.
226+
- `/var/mail`: User emails.
227+
- `/var/spool`: Files awaiting processing, such as print jobs.
14228

15-
A
229+
## /snap - Snap Packages
16230

231+
Present on systems using Snap, this directory stores applications in Snap format.
17232

591 KB
Loading
30.5 KB
Loading

0 commit comments

Comments
 (0)