smarken blog

Digital Sovrignty, Privacy, EU Law & Legislation, IT, Linux

Linux Fil struktur

- Indlæg i Linux - Generelt af

Linux-filsystemet

Roden og navigation

Linux-filsystemet er en kryptisk labyrint af mapper defineret af Filesystem Hierarchy Standard (FHS). Man navigerer med kommandoen cd (change directory). cd / bringer dig til roden. Med ls kan du se indholdet af en mappe.

Programfiler (binærer)

  • /bin – binærer/eksekverbare filer, der er essentielle for hele operativsystemet. De kan køres fra kommandolinjen når som helst, fx gzip, curl og ls-kommandoen selv.
  • /sbin – systembinærer, som kun bør køres af root-brugeren, fx mount eller deluser.
  • /lib – biblioteker (libraries), som mange af binærerne deler.
  • /usr/bin og /usr/sbin – binærer og programmer, der ikke er essentielle for selve operativsystemet, men er beregnet til slutbrugeren.
  • /usr/local – binærer, du kompilerer manuelt; et sikkert sted, der ikke konflikter med software installeret via systemets pakkehåndtering.

Alle disse binærer samles via PATH-miljøvariablen – derfor kan du køre dem fra enhver mappe i terminalen. Brug which efterfulgt af et programnavn for at se, hvor en binær ligger i filsystemet.

Konfiguration og brugere

  • /etc – "Editable Text Configuration" – konfigurationsfiler. Mange ender på .conf og er typisk almindelige tekstbaserede filer, du kan redigere i din editor.
  • /home – Linux understøtter flere brugere. Her findes en mappe pr. bruger med filer, konfiguration og software. Du skal være logget ind som brugeren (eller root) for at ændre den. Stien vises som ~ (tilde) – dit normale udgangspunkt, når du åbner en terminal.

Øvrige mapper i roden

Mappe Indhold
/boot Filer nødvendige for at boote systemet, selve Linux-kernen
/dev Enhedsfiler – her kan du tale med hardware/drivere, som var de almindelige filer (fx lave diskpartitioner)
/opt Valgfri/add-on-software – bruges sjældent
/var Variable filer, der ændrer sig under brug, fx logs og cache
/tmp Midlertidige filer, der ikke overlever genstarter
/proc Den mærkeligste: et virtuelt filsystem, der ikke findes på disken, men skabes i hukommelsen af kernen til at holde styr på kørende processer

Oversat og omorganiseret fra den transskriberede video af Mistral

Transcript

00:00 the Linux file system. It's a cryptic 00:03

00:03 labyrinth of directories defined by the 00:05

00:05 file system hierarchy standard. Navigate 00:08

00:08 through it with the change directory 00:09

00:09 command. CD forward slash drops you into 00:12

00:12 the root. Then with the ls command, we 00:14

00:14 can list out the contents of this 00:15

00:15 directory. First, we have the bin 00:17

00:17 directory which contains binaries or 00:19

00:19 executables that are essential to the 00:21

00:21 entire operating system. You can run 00:23

00:23 these binaries from the command line at 00:25

00:25 any time. Things like gzip, curl, and 00:27

00:27 even the ls command that we just ran. 00:29

00:29 But confusingly, there's also an espin 00:32

00:32 directory. It contains system binaries 00:34

00:34 that should only be executed by the root 00:36

00:36 user like mount or delete user. Many of 00:38

00:38 these binaries may share common 00:40

00:40 libraries which are stored in the lib 00:42

00:42 directory. Now, we also have a usr user 00:45

00:45 directory with its own bin and sbin 00:48

00:48 directories. The binaries or 00:49

00:49 applications here are non-essential to 00:51

00:51 the operating system itself and intended 00:53

00:53 for the end user. You'll also notice a 00:56

00:56 local directory under user. It contains 00:58

00:58 any binaries that you compile manually 01:00

01:00 to provide a safe place that won't 01:02

01:02 conflict with any software installed by 01:04

01:04 a system package manager. All these 01:06

01:06 binaries get mapped together with the 01:08

01:08 path environment variable. And that's 01:09

01:09 why you can execute them from any 01:11

01:11 directory in the terminal. If you ever 01:13

01:13 want to know where a binary lives, run 01:15

01:15 which followed by the binary name to 01:17

01:17 view its full path in the file system. 01:19

01:19 Now, at some point, you may want to 01:20

01:20 customize the behavior of the software 01:22

01:22 on your system. The etc directory stands 01:24

01:24 for etc or editable text configuration. 01:27

01:27 Many of these files end in domp and 01:29

01:29 they're typically just textbased config 01:31

01:31 files that you can modify in your 01:33

01:33 editor. As an operating system, Linux 01:35

01:35 can support multiple users. In the home 01:37

01:37 directory, you'll find a folder named 01:39

01:39 after each user registered on the 01:41

01:41 system. It contains the files, 01:42

01:42 configuration, and software for that 01:44

01:44 user, and you need to be logged in as 01:46

01:46 that user or as a root user to modify 01:48

01:48 it. Notice how the file path is a 01:50

01:50 squiggly. That's your normal starting 01:52

01:52 location when you open up a terminal 01:53

01:53 session. Now, let's go back to the root. 01:55

01:55 There are a few more directories here 01:57

01:57 that we haven't talked about yet, like 01:59

01:59 boot. It contains the files needed to 02:01

02:01 boot the system, like the Linux kernel 02:02

02:02 itself. Then, we have deb, which stands 02:05

02:05 for device files. Here, you can 02:06

02:06 interface with hardware or drivers as if 02:08

02:08 they were regular files. You might 02:10

02:10 create disk partitions here or interface 02:12

02:12 with your floppy drive. The op directory 02:14

02:14 contains optional or add-on software, 02:16

02:16 and you'll rarely interact with it. Var 02:19

02:19 contains variable files that will change 02:21

02:21 as the operating system is being used. 02:23

02:23 Things like logs and cache files. Temp 02:26

02:26 is for temporary files that won't be 02:28

02:28 persisted between reboots. And finally, 02:30

02:30 we have the weirdest one of all. The 02:31

02:31 proc directory is an illusionary file 02:34

02:34 system that doesn't actually exist on 02:35

02:35 the disk, but is created in memory on 02:38

02:38 the fly by the Linux kernel to keep 02:40

02:40 track of running processes. This has 02:42

02:42 been the Linux file system and thanks 02:43

02:43 for watching and I will see you in the 02:45

02:45 next