-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlinux.html
More file actions
1889 lines (1530 loc) · 97.2 KB
/
linux.html
File metadata and controls
1889 lines (1530 loc) · 97.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Learn Linux - Better Dev</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="topbar">
<button class="sidebar-toggle" aria-label="Open navigation" aria-expanded="false">
<span class="hamburger-icon"></span>
</button>
<a href="index.html" class="logo">Better Dev</a>
</header>
<div class="sidebar-backdrop" aria-hidden="true"></div>
<aside class="sidebar" aria-label="Site navigation">
<div class="sidebar-header">
<span class="sidebar-title">Navigation</span>
<button class="sidebar-close" aria-label="Close navigation">×</button>
</div>
<div class="sidebar-search">
<input type="text" class="sidebar-search-input" placeholder="Search topics..." aria-label="Search topics">
<div class="sidebar-search-results"></div>
</div>
<nav class="sidebar-nav">
<div class="sidebar-group">
<a href="index.html">Home</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Mathematics</div>
<a href="pre-algebra.html">Pre-Algebra</a>
<a href="algebra.html">Algebra</a>
<a href="sequences-series.html">Sequences & Series</a>
<a href="geometry.html">Geometry</a>
<a href="calculus.html">Calculus</a>
<a href="discrete-math.html">Discrete Math</a>
<a href="linear-algebra.html">Linear Algebra</a>
<a href="probability.html">Probability & Statistics</a>
<a href="binary-systems.html">Binary & Number Systems</a>
<a href="number-theory.html">Number Theory for CP</a>
<a href="computational-geometry.html">Computational Geometry</a>
<a href="game-theory.html">Game Theory</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Data Structures & Algorithms</div>
<a href="dsa-foundations.html">DSA Foundations</a>
<a href="arrays.html">Arrays & Strings</a>
<a href="stacks-queues.html">Stacks & Queues</a>
<a href="hashmaps.html">Hash Maps & Sets</a>
<a href="linked-lists.html">Linked Lists</a>
<a href="trees.html">Trees & BST</a>
<a href="graphs.html">Graphs</a>
<a href="sorting.html">Sorting & Searching</a>
<a href="patterns.html">LeetCode Patterns</a>
<a href="dp.html">Dynamic Programming</a>
<a href="advanced.html">Advanced Topics</a>
<a href="string-algorithms.html">String Algorithms</a>
<a href="advanced-graphs.html">Advanced Graphs</a>
<a href="advanced-dp.html">Advanced DP</a>
<a href="advanced-ds.html">Advanced Data Structures</a>
<a href="leetcode-650.html">The 650 Problems</a>
<a href="competitive-programming.html">CP Roadmap</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Languages & Systems</div>
<a href="cpp.html">C++</a>
<a href="golang.html">Go</a>
<a href="javascript.html">JavaScript Deep Dive</a>
<a href="typescript.html">TypeScript</a>
<a href="nodejs.html">Node.js Internals</a>
<a href="os.html">Operating Systems</a>
<a href="linux.html">Linux</a>
<a href="git.html">Git</a>
<a href="backend.html">Backend</a>
<a href="system-design.html">System Design</a>
<a href="networking.html">Networking</a>
<a href="cloud.html">Cloud & Infrastructure</a>
<a href="docker.html">Docker & Compose</a>
<a href="kubernetes.html">Kubernetes</a>
<a href="message-queues.html">Queues & Pub/Sub</a>
<a href="selfhosting.html">VPS & Self-Hosting</a>
<a href="databases.html">PostgreSQL & MySQL</a>
<a href="stripe.html">Stripe & Payments</a>
<a href="distributed-systems.html">Distributed Systems</a>
<a href="backend-engineering.html">Backend Engineering</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">JS/TS Ecosystem</div>
<a href="js-tooling.html">Tooling & Bundlers</a>
<a href="js-testing.html">Testing</a>
<a href="ts-projects.html">Building with TS</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">More</div>
<a href="seans-brain.html">Sean's Brain</a>
</div>
</nav>
</aside>
<div class="container">
<div class="page-header">
<div class="breadcrumb"><a href="index.html">Home</a> › <a href="os.html">Operating Systems</a> › Learn Linux</div>
<h1>Learn Linux</h1>
<p>Stop blindly copying and pasting commands. Understand what Linux actually is, how the kernel and shell work, what every directory does, how to use the terminal properly, and how to write your own Bash scripts. Built for Pop!_OS users who want to actually know their system.</p>
<div class="tip-box" style="margin-top: 1rem;">
<div class="label">You're Running Pop!_OS</div>
<p>Pop!_OS is an Ubuntu-based Linux distribution made by System76. Everything on this page applies directly to your system. When we say "Ubuntu" or "Debian", it applies to Pop!_OS too -- they share the same package manager (apt), the same directory structure, and the same underlying kernel.</p>
</div>
</div>
</div>
<div class="page-with-toc">
<aside class="sidebar-toc">
<div class="toc">
<h4>Table of Contents</h4>
<a href="#what-is-linux">1. What Is Linux?</a>
<a href="#unix-vs-linux">2. Unix vs Linux</a>
<a href="#distros">3. Linux Distros & Pop!_OS</a>
<a href="#kernel">4. The Kernel</a>
<a href="#shell">5. The Shell</a>
<a href="#terminal">6. Terminal & ANSI Escape Codes</a>
<a href="#directory-structure">7. Linux Directory Structure</a>
<a href="#users-permissions">8. Users & Permissions</a>
<a href="#package-management">9. Package Management (apt)</a>
<a href="#bash-basics">10. Bash Scripting Basics</a>
<a href="#bashrc">11. .bashrc & Shell Configuration</a>
<a href="#essential-commands">12. Essential Commands Cheat Sheet</a>
<a href="#environment">13. Environment Variables & PATH</a>
<a href="#processes-services">14. Processes & Services</a>
<a href="#quiz">15. Practice Quiz</a>
</div>
</aside>
<div class="content">
<!-- Mobile TOC -->
<div class="toc" style="margin-bottom: 2rem;">
<h4>Table of Contents</h4>
<a href="#what-is-linux">1. What Is Linux?</a>
<a href="#unix-vs-linux">2. Unix vs Linux</a>
<a href="#distros">3. Linux Distros & Pop!_OS</a>
<a href="#kernel">4. The Kernel</a>
<a href="#shell">5. The Shell</a>
<a href="#terminal">6. Terminal & ANSI Escape Codes</a>
<a href="#directory-structure">7. Linux Directory Structure</a>
<a href="#users-permissions">8. Users & Permissions</a>
<a href="#package-management">9. Package Management (apt)</a>
<a href="#bash-basics">10. Bash Scripting Basics</a>
<a href="#bashrc">11. .bashrc & Shell Configuration</a>
<a href="#essential-commands">12. Essential Commands Cheat Sheet</a>
<a href="#environment">13. Environment Variables & PATH</a>
<a href="#processes-services">14. Processes & Services</a>
<a href="#quiz">15. Practice Quiz</a>
</div>
<!-- ============================================================ -->
<!-- SECTION 1: WHAT IS LINUX? -->
<!-- ============================================================ -->
<section id="what-is-linux">
<h2>1. What Is Linux?</h2>
<p><strong>Linux</strong> is an operating system kernel -- the core piece of software that talks to your hardware (CPU, RAM, disk, GPU) and lets programs run on top of it. It was created in 1991 by Linus Torvalds, a Finnish computer science student, as a free alternative to the expensive Unix operating systems that universities and companies used.</p>
<p>When people say "Linux" they usually mean a complete operating system built around the Linux kernel. Technically, the full stack is:</p>
<div class="memory-diagram">
┌─────────────────────────────────────┐
│ Your Applications │ ← Firefox, VS Code, terminal, etc.
│ (GUI apps, CLI tools, scripts) │
├─────────────────────────────────────┤
│ Desktop Environment │ ← COSMIC (Pop!_OS), GNOME, KDE
│ (window manager, panels, themes) │
├─────────────────────────────────────┤
│ System Libraries & Utilities │ ← GNU coreutils, glibc, systemd
│ (ls, cp, cat, bash, apt, etc.) │
├─────────────────────────────────────┤
│ Linux Kernel │ ← The actual "Linux" part
│ (process mgmt, memory, drivers, │
│ filesystems, networking) │
├─────────────────────────────────────┤
│ Hardware │ ← CPU, RAM, SSD, GPU, NIC
└─────────────────────────────────────┘</div>
<p>The kernel alone isn't useful -- you need all the tools around it (shell, file utilities, package manager, display server) to have a working system. That's why some people call it <strong>GNU/Linux</strong> -- because most of those utilities come from the GNU project (started by Richard Stallman in 1983).</p>
<h3>Why Linux Matters for Developers</h3>
<ul>
<li><strong>Servers run Linux</strong> -- over 96% of the world's top web servers run Linux. If you deploy code, you're deploying to Linux.</li>
<li><strong>It's open source</strong> -- you can read the kernel source code, modify it, and understand exactly what your computer is doing. No black boxes.</li>
<li><strong>The terminal is first-class</strong> -- unlike Windows where the terminal is an afterthought, Linux was built around the command line. Most development tools assume a Unix-like environment.</li>
<li><strong>Containers are Linux</strong> -- Docker, Kubernetes, and all container tech runs on the Linux kernel (namespaces + cgroups).</li>
<li><strong>It's free</strong> -- no license costs, no activation keys, no forced updates.</li>
</ul>
<div class="tip-box">
<div class="label">Open Source Means You Can Learn</div>
<p>Every command you run on Linux is open source. Curious how <code>ls</code> works? You can read the actual C source code. Wondering what <code>apt</code> does when it installs a package? You can read the Python source. This is incredibly powerful for learning.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 2: UNIX VS LINUX -->
<!-- ============================================================ -->
<section id="unix-vs-linux">
<h2>2. Unix vs Linux</h2>
<p>You'll hear "Unix" and "Linux" used interchangeably, but they're different things with a shared history.</p>
<h3>The History (Quick Version)</h3>
<ol>
<li><strong>1969</strong> -- Ken Thompson and Dennis Ritchie create Unix at AT&T Bell Labs. It's written in C (which Ritchie also created). Unix introduces revolutionary ideas: "everything is a file", pipes, a hierarchical filesystem, and the shell.</li>
<li><strong>1970s-80s</strong> -- Unix spreads to universities. Different versions appear: BSD (Berkeley), System V (AT&T), SunOS, HP-UX, AIX. Each is proprietary and expensive.</li>
<li><strong>1983</strong> -- Richard Stallman starts the GNU project to create a free Unix-like system. He builds all the user-space tools (compiler, shell, utilities) but the kernel (GNU Hurd) is never finished.</li>
<li><strong>1991</strong> -- Linus Torvalds writes the Linux kernel as a hobby project. Combined with GNU tools, it becomes a complete free Unix-like operating system.</li>
<li><strong>Today</strong> -- Linux dominates servers, phones (Android), embedded devices, supercomputers (100% of the top 500), and is increasingly popular on desktops.</li>
</ol>
<h3>Key Differences</h3>
<table>
<tr><th>Aspect</th><th>Unix</th><th>Linux</th></tr>
<tr><td>Origin</td><td>AT&T Bell Labs, 1969</td><td>Linus Torvalds, 1991</td></tr>
<tr><td>License</td><td>Proprietary (mostly)</td><td>GPL (free and open source)</td></tr>
<tr><td>Source code</td><td>Closed (mostly)</td><td>Fully open</td></tr>
<tr><td>Cost</td><td>Expensive licenses</td><td>Free</td></tr>
<tr><td>Examples</td><td>macOS, Solaris, HP-UX, AIX</td><td>Ubuntu, Fedora, Pop!_OS, Arch, Debian</td></tr>
<tr><td>Kernel</td><td>Various (XNU for macOS, etc.)</td><td>Linux kernel</td></tr>
<tr><td>Hardware</td><td>Often tied to specific hardware</td><td>Runs on almost anything</td></tr>
<tr><td>POSIX</td><td>Certified POSIX compliant</td><td>Mostly POSIX compliant (not certified)</td></tr>
</table>
<h3>Unix-like vs Unix</h3>
<p>Linux is <strong>Unix-like</strong> -- it behaves like Unix, follows similar conventions, and programs written for Unix usually work on Linux. But it's not Unix. It doesn't share any code with the original AT&T Unix. It was written from scratch.</p>
<p><strong>macOS</strong> is actually certified Unix. Under the hood, macOS runs a Unix kernel called XNU (derived from BSD). That's why the macOS terminal feels similar to Linux -- they share Unix roots.</p>
<h3>POSIX -- The Standard</h3>
<p><strong>POSIX</strong> (Portable Operating System Interface) is a set of standards that defines how a Unix-like operating system should behave. It specifies things like:</p>
<ul>
<li>What system calls must exist (open, read, write, fork, exec...)</li>
<li>How the shell should work</li>
<li>What utilities must be available (ls, grep, awk, sed...)</li>
<li>How regular expressions work</li>
</ul>
<p>Both Unix systems and Linux follow POSIX (mostly). This is why shell scripts and command-line tools work across different Unix-like systems.</p>
<div class="warning-box">
<div class="label">Key Takeaway</div>
<p>Linux is a free, open-source reimplementation of Unix ideas. It's not Unix, but it works like Unix. When a tutorial says "Unix/Linux" or "POSIX", the commands will work on your Pop!_OS system.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 3: DISTROS & POP!_OS -->
<!-- ============================================================ -->
<section id="distros">
<h2>3. Linux Distros & Pop!_OS</h2>
<p>A <strong>Linux distribution (distro)</strong> is a complete operating system built around the Linux kernel. Different distros package different software, use different package managers, and target different users. But they all share the same kernel.</p>
<h3>The Family Tree</h3>
<div class="memory-diagram">
Linux Kernel
│
├── Debian ─────────── Ubuntu ─────── Pop!_OS ← YOU ARE HERE
│ │
│ ├── Linux Mint
│ └── Elementary OS
│
├── Red Hat (RHEL) ──── Fedora
│ │
│ └── CentOS / Rocky Linux
│
├── Arch Linux ─────── Manjaro
│ └── EndeavourOS
│
├── SUSE ───────────── openSUSE
│
├── Gentoo
│
└── Slackware (oldest active distro)</div>
<h3>Major Distro Families</h3>
<table>
<tr><th>Family</th><th>Package Manager</th><th>Package Format</th><th>Notable Distros</th></tr>
<tr><td><strong>Debian</strong></td><td>apt / dpkg</td><td>.deb</td><td>Debian, Ubuntu, Pop!_OS, Mint</td></tr>
<tr><td><strong>Red Hat</strong></td><td>dnf / rpm</td><td>.rpm</td><td>Fedora, RHEL, CentOS, Rocky</td></tr>
<tr><td><strong>Arch</strong></td><td>pacman</td><td>.pkg.tar.zst</td><td>Arch, Manjaro, EndeavourOS</td></tr>
<tr><td><strong>SUSE</strong></td><td>zypper / rpm</td><td>.rpm</td><td>openSUSE Tumbleweed/Leap</td></tr>
</table>
<h3>Your Distro: Pop!_OS</h3>
<p>Pop!_OS is made by <strong>System76</strong>, a company that builds Linux laptops and desktops. Here's what makes it special:</p>
<ul>
<li><strong>Based on Ubuntu</strong> -- which is based on Debian. So you can use <code>apt</code> to install packages, and most Ubuntu tutorials work on Pop!_OS.</li>
<li><strong>COSMIC desktop</strong> -- System76 built their own desktop environment. It has auto-tiling windows, a clean design, and is written in Rust.</li>
<li><strong>Pop!_Shop</strong> -- a graphical app store (Flatpak-based) for installing software.</li>
<li><strong>Built for developers</strong> -- comes with good defaults, GPU switching for NVIDIA/AMD, and recovery partition.</li>
<li><strong>systemd-boot</strong> -- uses systemd-boot instead of GRUB as the bootloader (simpler and faster).</li>
</ul>
<p>To check your system info:</p>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># What distro are you running?</span>
$ cat /etc/os-release
NAME="Pop!_OS"
VERSION="22.04 LTS"
ID=pop
ID_LIKE="ubuntu debian"
<span class="comment"># What kernel version?</span>
$ uname -r
6.17.9-76061709-generic
<span class="comment"># System architecture</span>
$ uname -m
x86_64
<span class="comment"># All system info in one shot</span>
$ hostnamectl</code></pre>
<div class="tip-box">
<div class="label">Ubuntu Compatibility</div>
<p>Since Pop!_OS is based on Ubuntu, you can use Ubuntu PPAs, Ubuntu tutorials, and Ubuntu .deb packages. If you're searching for how to do something, search "Ubuntu" + your question -- it will almost always work on Pop!_OS too.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 4: THE KERNEL -->
<!-- ============================================================ -->
<section id="kernel">
<h2>4. The Kernel</h2>
<p>The <strong>kernel</strong> is the core of the operating system. It's the one piece of software that runs in <strong>kernel mode</strong> (privileged mode) with full access to hardware. Everything else -- your browser, your terminal, your text editor -- runs in user mode and must ask the kernel for permission to do anything hardware-related.</p>
<h3>What the Kernel Does</h3>
<div class="memory-diagram">
THE LINUX KERNEL
┌─────────────────────────────────────────────┐
│ │
│ Process Management │
│ ├── Create/destroy processes (fork/exit) │
│ ├── Schedule which process runs next │
│ └── Context switching between processes │
│ │
│ Memory Management │
│ ├── Virtual memory (page tables) │
│ ├── Allocate/free physical memory │
│ └── Swap pages to/from disk │
│ │
│ Device Drivers │
│ ├── Talk to hardware (GPU, NIC, USB) │
│ ├── Expose devices as files in /dev │
│ └── Handle interrupts from devices │
│ │
│ File Systems │
│ ├── ext4, btrfs, xfs, ntfs, fat32 │
│ ├── Virtual filesystems (/proc, /sys) │
│ └── File permissions enforcement │
│ │
│ Networking │
│ ├── TCP/IP stack │
│ ├── Socket API │
│ ├── Firewall (netfilter/iptables) │
│ └── Network device drivers │
│ │
│ Security │
│ ├── User/group permissions │
│ ├── Namespaces (containers) │
│ ├── cgroups (resource limits) │
│ └── SELinux/AppArmor │
│ │
└─────────────────────────────────────────────┘</div>
<h3>How Programs Talk to the Kernel</h3>
<p>Programs can't call kernel functions directly. They use <strong>system calls (syscalls)</strong> -- a special CPU instruction that switches from user mode to kernel mode. When you call <code>open()</code>, <code>read()</code>, <code>write()</code>, <code>fork()</code>, etc., you're making syscalls. (See the <a href="os.html#syscalls" class="resource-link">OS page section on syscalls</a> for the full details.)</p>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># See kernel version</span>
$ uname -r
6.17.9-76061709-generic
<span class="comment"># See kernel messages (hardware detection, driver loading, errors)</span>
$ dmesg | tail -20
<span class="comment"># See loaded kernel modules (drivers)</span>
$ lsmod
<span class="comment"># Kernel configuration</span>
$ cat /boot/config-$(uname -r) | head
<span class="comment"># See kernel parameters</span>
$ sysctl -a | head</code></pre>
<h3>Monolithic vs Microkernel</h3>
<p>Linux is a <strong>monolithic kernel</strong> -- all the core services (process management, file systems, device drivers, networking) run in kernel space. This is fast because there's no overhead of message passing between components.</p>
<p>The alternative is a <strong>microkernel</strong> (like GNU Hurd or MINIX) where only the bare minimum runs in kernel mode and everything else runs as user-space servers. More secure and modular, but slower due to inter-process communication overhead.</p>
<p>Linux uses <strong>loadable kernel modules</strong> as a middle ground -- drivers can be loaded and unloaded at runtime without rebooting:</p>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># List loaded modules</span>
$ lsmod
<span class="comment"># Info about a module</span>
$ modinfo nvidia
<span class="comment"># Load a module (requires sudo)</span>
$ sudo modprobe module_name
<span class="comment"># Unload a module</span>
$ sudo rmmod module_name</code></pre>
<div class="warning-box">
<div class="label">The Kernel Is Not the OS</div>
<p>The kernel is just one part of the operating system. It manages hardware and provides services. But without a shell, file utilities, a package manager, and a desktop environment, a kernel alone is useless. That's what distros provide -- everything around the kernel to make a usable system.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 5: THE SHELL -->
<!-- ============================================================ -->
<section id="shell">
<h2>5. The Shell</h2>
<p>The <strong>shell</strong> is a program that reads commands you type, interprets them, and asks the kernel to execute them. It's the text-based interface between you and the operating system. When you open a terminal on Pop!_OS, the shell is the program running inside it.</p>
<h3>How the Shell Works</h3>
<div class="memory-diagram">
You type: ls -la /home
┌──────────────┐
│ Terminal │ ← The window (GUI application)
│ Emulator │ (e.g., GNOME Terminal, Alacritty)
└──────┬───────┘
│ sends keystrokes
▼
┌──────────────┐
│ Shell │ ← The interpreter (e.g., bash, zsh)
│ (bash) │ Parses "ls -la /home"
└──────┬───────┘
│ fork() + exec("ls", "-la", "/home")
▼
┌──────────────┐
│ Kernel │ ← Creates process, runs ls binary
└──────┬───────┘
│ ls reads directory, writes to stdout
▼
Output appears in your terminal</div>
<p>The shell is NOT the terminal. The <strong>terminal emulator</strong> is the GUI window. The <strong>shell</strong> is the program running inside it that actually processes your commands.</p>
<h3>Common Shells</h3>
<table>
<tr><th>Shell</th><th>Binary</th><th>Notes</th></tr>
<tr><td><strong>bash</strong></td><td>/bin/bash</td><td>Bourne Again Shell. Default on most Linux distros including Pop!_OS. The one you should learn first.</td></tr>
<tr><td><strong>zsh</strong></td><td>/bin/zsh</td><td>Z Shell. Default on macOS. More features than bash (better autocomplete, themes). Compatible with bash mostly.</td></tr>
<tr><td><strong>fish</strong></td><td>/usr/bin/fish</td><td>Friendly Interactive Shell. Great autosuggestions and syntax highlighting out of the box. NOT bash-compatible.</td></tr>
<tr><td><strong>sh</strong></td><td>/bin/sh</td><td>Bourne Shell (POSIX shell). Minimal. Used for scripts that need maximum portability.</td></tr>
<tr><td><strong>dash</strong></td><td>/bin/dash</td><td>Debian Almquist Shell. What <code>/bin/sh</code> points to on Debian/Ubuntu/Pop!_OS. Very fast, minimal.</td></tr>
</table>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># What shell am I using?</span>
$ echo $SHELL
/bin/bash
<span class="comment"># What shells are installed?</span>
$ cat /etc/shells
<span class="comment"># Change your default shell to zsh</span>
$ chsh -s /bin/zsh
<span class="comment"># Temporarily use a different shell</span>
$ zsh <span class="comment"># starts zsh session</span>
$ exit <span class="comment"># back to previous shell</span></code></pre>
<h3>Shell Features You Should Know</h3>
<h4>Tab Completion</h4>
<p>Press <code>Tab</code> to autocomplete commands, file names, and paths. Press <code>Tab</code> twice to see all possibilities. This is the single most important productivity feature. Stop typing full file names.</p>
<h4>Command History</h4>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Search history (most useful shortcut in bash)</span>
Ctrl+R then type part of a previous command
<span class="comment"># Show recent commands</span>
$ history | tail -20
<span class="comment"># Re-run the last command</span>
$ !!
<span class="comment"># Re-run last command starting with "git"</span>
$ !git
<span class="comment"># Run previous command with sudo</span>
$ sudo !!</code></pre>
<h4>Pipes and Redirection</h4>
<p>This is the <em>fundamental</em> Unix philosophy: small programs that do one thing well, connected together with pipes.</p>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Pipe: send stdout of one command to stdin of another</span>
$ ls -la | grep ".txt" <span class="comment"># list files, filter for .txt</span>
$ cat log.txt | sort | uniq -c <span class="comment"># count unique lines</span>
$ ps aux | grep firefox <span class="comment"># find firefox processes</span>
<span class="comment"># Redirect stdout to a file (overwrites)</span>
$ echo "hello" > output.txt
<span class="comment"># Redirect stdout to a file (appends)</span>
$ echo "world" >> output.txt
<span class="comment"># Redirect stderr to a file</span>
$ ./my_script 2> errors.txt
<span class="comment"># Redirect both stdout and stderr</span>
$ ./my_script > output.txt 2>&1
<span class="comment"># Discard output (send to /dev/null -- the void)</span>
$ ./noisy_program > /dev/null 2>&1
<span class="comment"># Use a file as stdin</span>
$ sort < unsorted.txt</code></pre>
<h4>Keyboard Shortcuts (Bash)</h4>
<table>
<tr><th>Shortcut</th><th>What It Does</th></tr>
<tr><td><code>Ctrl+C</code></td><td>Kill the current running command (sends SIGINT)</td></tr>
<tr><td><code>Ctrl+D</code></td><td>Exit the shell / send EOF</td></tr>
<tr><td><code>Ctrl+Z</code></td><td>Suspend the current process (put it in background)</td></tr>
<tr><td><code>Ctrl+L</code></td><td>Clear the screen</td></tr>
<tr><td><code>Ctrl+A</code></td><td>Move cursor to beginning of line</td></tr>
<tr><td><code>Ctrl+E</code></td><td>Move cursor to end of line</td></tr>
<tr><td><code>Ctrl+W</code></td><td>Delete the word before the cursor</td></tr>
<tr><td><code>Ctrl+U</code></td><td>Delete from cursor to beginning of line</td></tr>
<tr><td><code>Ctrl+R</code></td><td>Reverse search through command history</td></tr>
<tr><td><code>Alt+.</code></td><td>Insert the last argument of the previous command</td></tr>
</table>
<div class="formula-box">
<strong>Shell Command Lookup Order (Exact):</strong><br><br>
1. Aliases (defined with <code>alias</code>)<br>
2. Functions (defined with <code>function name() {}</code>)<br>
3. Built-in commands (<code>cd</code>, <code>echo</code>, <code>export</code>)<br>
4. External programs (searched in PATH, left to right)<br><br>
<strong>Check which is used:</strong> <code>type commandname</code>
</div>
<div class="tip-box">
<div class="label">Start With Bash</div>
<p>Learn bash first. It's the default everywhere, all tutorials assume it, and scripts are written in it. Once you're comfortable, try zsh or fish for your interactive shell -- but always know bash because that's what servers run.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 6: TERMINAL & ANSI ESCAPE CODES -->
<!-- ============================================================ -->
<section id="terminal">
<h2>6. Terminal & ANSI Escape Codes</h2>
<p>The <strong>terminal emulator</strong> (GNOME Terminal, Alacritty, kitty, etc.) is a GUI application that emulates the old hardware terminals from the 1970s. It displays text, accepts keyboard input, and understands special character sequences called <strong>ANSI escape codes</strong>.</p>
<h3>What's a Terminal?</h3>
<div class="memory-diagram">
The Old Days (1970s): Today:
┌──────────────────┐ ┌──────────────────┐
│ VT100 Terminal │ physical │ Terminal │ software
│ (hardware) │ device │ Emulator (GUI) │ application
│ │ │ │
│ CRT screen │ │ ┌─────────────┐ │
│ + keyboard │ │ │ Shell │ │
│ connected via │ │ │ (bash/zsh) │ │
│ serial cable │ │ └─────────────┘ │
│ to mainframe │ │ │
└──────────────────┘ └──────────────────┘</div>
<p>Terminal emulators pretend to be those old hardware terminals. The protocol they use (ANSI escape sequences) is the same one from the 1970s VT100 terminal, just extended over the decades.</p>
<h3>ANSI Escape Codes</h3>
<p>An <strong>ANSI escape code</strong> is a special sequence of characters that starts with <code>ESC[</code> (escape character followed by <code>[</code>). The terminal interprets these sequences as formatting commands instead of printing them as text.</p>
<p>The escape character is <code>\033</code> (octal), <code>\x1b</code> (hex), or <code>\e</code> (bash shorthand). It's ASCII code 27.</p>
<h4>Text Colors</h4>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Format: \033[CODEm (the 'm' at the end is required)</span>
<span class="comment"># Basic colors (foreground)</span>
echo -e "\033[31mRed text\033[0m"
echo -e "\033[32mGreen text\033[0m"
echo -e "\033[33mYellow text\033[0m"
echo -e "\033[34mBlue text\033[0m"
echo -e "\033[35mMagenta text\033[0m"
echo -e "\033[36mCyan text\033[0m"
<span class="comment"># \033[0m resets formatting back to default (always reset!)</span>
<span class="comment"># Background colors (add 10 to the foreground code)</span>
echo -e "\033[41mRed background\033[0m"
echo -e "\033[42mGreen background\033[0m"
<span class="comment"># Bold, underline, etc.</span>
echo -e "\033[1mBold\033[0m"
echo -e "\033[4mUnderlined\033[0m"
echo -e "\033[1;31mBold Red\033[0m"
<span class="comment"># Combine multiple styles with semicolons</span>
echo -e "\033[1;4;33mBold underlined yellow\033[0m"</code></pre>
<h4>Color Code Reference</h4>
<table>
<tr><th>Code</th><th>Foreground</th><th>Background</th></tr>
<tr><td>30 / 40</td><td>Black</td><td>Black</td></tr>
<tr><td>31 / 41</td><td>Red</td><td>Red</td></tr>
<tr><td>32 / 42</td><td>Green</td><td>Green</td></tr>
<tr><td>33 / 43</td><td>Yellow</td><td>Yellow</td></tr>
<tr><td>34 / 44</td><td>Blue</td><td>Blue</td></tr>
<tr><td>35 / 45</td><td>Magenta</td><td>Magenta</td></tr>
<tr><td>36 / 46</td><td>Cyan</td><td>Cyan</td></tr>
<tr><td>37 / 47</td><td>White</td><td>White</td></tr>
</table>
<table>
<tr><th>Code</th><th>Effect</th></tr>
<tr><td>0</td><td>Reset all formatting</td></tr>
<tr><td>1</td><td>Bold / bright</td></tr>
<tr><td>2</td><td>Dim</td></tr>
<tr><td>4</td><td>Underline</td></tr>
<tr><td>5</td><td>Blink (not supported everywhere)</td></tr>
<tr><td>7</td><td>Reverse (swap foreground/background)</td></tr>
</table>
<h4>256 Color and True Color</h4>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># 256 color mode: \033[38;5;COLORm (foreground)</span>
echo -e "\033[38;5;208mOrange text (color 208)\033[0m"
echo -e "\033[48;5;21mBlue background (color 21)\033[0m"
<span class="comment"># True color (24-bit RGB): \033[38;2;R;G;Bm</span>
echo -e "\033[38;2;255;100;0mRGB orange\033[0m"
echo -e "\033[48;2;0;50;100mRGB dark blue bg\033[0m"</code></pre>
<h4>Cursor Movement</h4>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Move cursor up/down/forward/back</span>
echo -e "\033[2A" <span class="comment"># move up 2 lines</span>
echo -e "\033[3B" <span class="comment"># move down 3 lines</span>
echo -e "\033[5C" <span class="comment"># move forward 5 columns</span>
echo -e "\033[2D" <span class="comment"># move back 2 columns</span>
<span class="comment"># Move to specific position (row;column)</span>
echo -e "\033[10;20H" <span class="comment"># move to row 10, column 20</span>
<span class="comment"># Clear screen</span>
echo -e "\033[2J" <span class="comment"># clear entire screen</span>
echo -e "\033[K" <span class="comment"># clear from cursor to end of line</span>
<span class="comment"># Save and restore cursor position</span>
echo -e "\033[s" <span class="comment"># save position</span>
echo -e "\033[u" <span class="comment"># restore position</span></code></pre>
<h4>Why ANSI Codes Matter</h4>
<p>ANSI codes are how every colorful CLI tool works:</p>
<ul>
<li><code>ls --color</code> uses ANSI codes to color directories blue, executables green, etc.</li>
<li><code>git diff</code> uses red/green ANSI codes for removed/added lines</li>
<li>Your shell prompt (PS1) uses ANSI codes for colors</li>
<li>Progress bars in <code>npm install</code>, <code>pip install</code> use cursor movement codes</li>
<li>Text editors like <code>vim</code> and <code>nano</code> use ANSI codes to render the entire UI</li>
</ul>
<div class="example-box">
<div class="label">Try It: Custom Colored Prompt</div>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># A colorful bash prompt with username, directory, and git branch</span>
export PS1="\[\033[1;32m\]\u\[\033[0m\]@\[\033[1;34m\]\h\[\033[0m\]:\[\033[1;33m\]\w\[\033[0m\]\$ "
<span class="comment"># \u = username, \h = hostname, \w = working directory</span>
<span class="comment"># \[...\] tells bash not to count these characters for line wrapping</span></code></pre>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 7: LINUX DIRECTORY STRUCTURE -->
<!-- ============================================================ -->
<section id="directory-structure">
<h2>7. Linux Directory Structure (FHS)</h2>
<p>Linux uses a single directory tree starting from <code>/</code> (root). There are no drive letters like <code>C:\</code> on Windows. Everything -- your files, devices, running processes -- lives somewhere in this tree. The layout follows the <strong>Filesystem Hierarchy Standard (FHS)</strong>.</p>
<div class="memory-diagram">
/ ← Root of everything
├── bin/ ← Essential command binaries (ls, cp, cat, bash)
├── sbin/ ← System binaries (fdisk, iptables, mount)
├── boot/ ← Kernel and bootloader files
├── dev/ ← Device files (every hardware device is a file here)
│ ├── sda ← First hard drive
│ ├── sda1 ← First partition of first drive
│ ├── null ← The void (discards anything written to it)
│ ├── zero ← Infinite stream of zero bytes
│ ├── random ← Random bytes (for encryption keys etc.)
│ └── tty ← Your terminal
├── etc/ ← System configuration files (text files you edit)
│ ├── fstab ← Filesystem mount points
│ ├── hostname ← Your computer's name
│ ├── hosts ← Local DNS overrides
│ ├── passwd ← User account info
│ ├── shadow ← Password hashes (root only)
│ ├── apt/ ← APT package manager config
│ │ └── sources.list.d/ ← Package repository URLs
│ └── systemd/ ← Service configuration
├── home/ ← User home directories
│ └── sean/ ← YOUR stuff lives here
│ ├── Desktop/
│ ├── Documents/
│ ├── Downloads/
│ ├── .bashrc ← Your shell configuration
│ ├── .config/ ← App configs (XDG standard)
│ ├── .local/ ← User-installed programs and data
│ └── .ssh/ ← SSH keys
├── lib/ ← Shared libraries (like .dll on Windows)
├── media/ ← Auto-mounted removable drives (USB, CD)
├── mnt/ ← Manually mounted filesystems
├── opt/ ← Optional third-party software
├── proc/ ← Virtual filesystem -- running process info
│ ├── cpuinfo ← CPU details
│ ├── meminfo ← Memory details
│ └── [pid]/ ← Info about each running process
├── root/ ← Root user's home directory (not /home/root)
├── run/ ← Runtime data (PIDs, sockets) -- cleared on reboot
├── srv/ ← Data for services (web server files, etc.)
├── sys/ ← Virtual filesystem -- hardware/driver info
├── tmp/ ← Temporary files (cleared on reboot)
├── usr/ ← User programs and data (read-only)
│ ├── bin/ ← Most user commands (git, python, gcc, node)
│ ├── lib/ ← Libraries for /usr/bin programs
│ ├── local/ ← Locally compiled software
│ │ ├── bin/ ← Your manually installed programs
│ │ └── lib/
│ ├── share/ ← Architecture-independent data (docs, icons)
│ └── include/ ← C/C++ header files
└── var/ ← Variable data (changes during operation)
├── log/ ← System logs
│ ├── syslog ← General system log
│ └── auth.log ← Authentication log
├── cache/ ← Application caches (apt downloads etc.)
├── lib/ ← Variable state data (databases, package info)
└── tmp/ ← Persistent temp files (survives reboot)</div>
<h3>The Most Important Directories for You</h3>
<table>
<tr><th>Directory</th><th>What You Use It For</th></tr>
<tr><td><code>~</code> (home)</td><td>Your files, projects, configs. <code>cd ~</code> or just <code>cd</code> goes here.</td></tr>
<tr><td><code>/etc</code></td><td>When you need to configure system software (nginx, ssh, network, etc.)</td></tr>
<tr><td><code>/var/log</code></td><td>When something breaks -- check the logs here.</td></tr>
<tr><td><code>/tmp</code></td><td>Throw temporary files here. Cleared on reboot.</td></tr>
<tr><td><code>/usr/bin</code></td><td>Where most programs live. <code>which python3</code> shows you the exact path.</td></tr>
<tr><td><code>/dev</code></td><td>Device files. <code>/dev/null</code> is your best friend for discarding output.</td></tr>
<tr><td><code>/proc</code></td><td>Process and system info. <code>cat /proc/cpuinfo</code> shows CPU details.</td></tr>
</table>
<h3>Everything Is a File</h3>
<p>This is the fundamental Unix philosophy. In Linux, <em>everything</em> is represented as a file:</p>
<ul>
<li><strong>Regular files</strong> -- text, images, binaries. The obvious ones.</li>
<li><strong>Directories</strong> -- special files that contain lists of other files.</li>
<li><strong>Device files</strong> (<code>/dev/sda</code>) -- reading/writing these talks directly to hardware.</li>
<li><strong>Pipes</strong> (<code>|</code>) -- connect the output of one program to the input of another.</li>
<li><strong>Sockets</strong> -- network connections and inter-process communication.</li>
<li><strong>Symlinks</strong> -- pointers to other files.</li>
<li><strong>Process info</strong> (<code>/proc/1234/status</code>) -- kernel data exposed as readable files.</li>
</ul>
<div class="example-box">
<div class="label">Example: Exploring Your System</div>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># How much disk space is each top-level directory using?</span>
$ sudo du -sh /* 2>/dev/null | sort -hr | head -10
<span class="comment"># What's in /dev? (your devices)</span>
$ ls /dev | head -20
<span class="comment"># Read your CPU info (it's just a "file")</span>
$ cat /proc/cpuinfo | grep "model name" | head -1
<span class="comment"># How long has your system been running?</span>
$ cat /proc/uptime
<span class="comment"># What filesystems are mounted?</span>
$ df -h</code></pre>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 8: USERS & PERMISSIONS -->
<!-- ============================================================ -->
<section id="users-permissions">
<h2>8. Users & Permissions</h2>
<p>Linux is a multi-user system. Every file is owned by a user and a group, and has permission bits that control who can read, write, or execute it.</p>
<h3>Users and Groups</h3>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Who am I?</span>
$ whoami
sean
<span class="comment"># What groups am I in?</span>
$ groups
sean adm cdrom sudo dip plugdev lpadmin
<span class="comment"># User info (from /etc/passwd)</span>
$ id
uid=1000(sean) gid=1000(sean) groups=1000(sean),27(sudo),...
<span class="comment"># The root user (UID 0) can do ANYTHING</span>
<span class="comment"># Use sudo to run commands as root</span>
$ sudo apt update</code></pre>
<h3>Permission Bits</h3>
<div class="formula-box">
$ ls -la
drwxr-xr-x 2 sean sean 4096 Feb 23 10:30 Documents
-rw-r--r-- 1 sean sean 156 Feb 23 10:30 notes.txt
-rwxr-xr-x 1 sean sean 892 Feb 23 10:30 script.sh
lrwxrwxrwx 1 sean sean 11 Feb 23 10:30 link -> target.txt
│├─┤├─┤├─┤
│ │ │ └── Others (everyone else)
│ │ └───── Group
│ └──────── Owner
└────────── Type: d=dir, -=file, l=symlink
r = read (4) w = write (2) x = execute (1)
</div>
<p>For <strong>files</strong>: r = read the contents, w = modify it, x = run it as a program.</p>
<p>For <strong>directories</strong>: r = list contents (ls), w = create/delete files inside, x = enter the directory (cd).</p>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Change permissions (numeric)</span>
$ chmod 755 script.sh <span class="comment"># rwxr-xr-x (owner: all, group/others: read+exec)</span>
$ chmod 644 notes.txt <span class="comment"># rw-r--r-- (owner: read+write, group/others: read)</span>
$ chmod 700 private/ <span class="comment"># rwx------ (owner only)</span>
<span class="comment"># Change permissions (symbolic)</span>
$ chmod +x script.sh <span class="comment"># add execute for everyone</span>
$ chmod u+x script.sh <span class="comment"># add execute for owner only</span>
$ chmod go-w file.txt <span class="comment"># remove write for group and others</span>
<span class="comment"># Change ownership</span>
$ sudo chown sean:sean file.txt
$ sudo chown -R sean:sean directory/ <span class="comment"># recursive</span></code></pre>
<h3>sudo -- Doing Things as Root</h3>
<p><code>sudo</code> (superuser do) runs a single command as root. Your user must be in the <code>sudo</code> group. On Pop!_OS, your first user is automatically in the sudo group.</p>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Install software (needs root)</span>
$ sudo apt install git
<span class="comment"># Edit a system config file</span>
$ sudo nano /etc/hosts
<span class="comment"># Become root for multiple commands (use sparingly)</span>
$ sudo -i <span class="comment"># opens a root shell</span>
# exit <span class="comment"># go back to your user</span>
<span class="comment"># Run the last command with sudo</span>
$ apt update <span class="comment"># oops, permission denied</span>
$ sudo !! <span class="comment"># runs "sudo apt update"</span></code></pre>
<div class="warning-box">
<div class="label">Don't Run Everything as Root</div>
<p>Only use <code>sudo</code> when you actually need elevated privileges (installing software, editing system files, managing services). Running everyday commands as root is dangerous -- a typo like <code>sudo rm -rf /</code> would destroy your entire system. The permission system exists to protect you from yourself.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 9: PACKAGE MANAGEMENT (APT) -->
<!-- ============================================================ -->
<section id="package-management">
<h2>9. Package Management (apt)</h2>
<p>On Linux, you don't download .exe files from websites. Instead, you use a <strong>package manager</strong> that downloads, installs, updates, and removes software from trusted <strong>repositories</strong> (servers that host packages).</p>
<p>Pop!_OS uses <code>apt</code> (Advanced Package Tool) because it's Debian/Ubuntu-based. Packages are <code>.deb</code> files.</p>
<h3>How apt Works</h3>
<div class="memory-diagram">
Your machine Remote repository
──────────── (e.g., archive.ubuntu.com)
┌──────────────────────┐
$ sudo apt update ──────────────→ │ Package lists │
(downloads package lists) │ (what's available) │
└──────────────────────┘
$ sudo apt install git ──────────→ ┌──────────────────────┐
(downloads .deb files) │ .deb package files │
installs them locally │ (actual software) │
└──────────────────────┘
apt handles:
- Downloading packages
- Resolving dependencies (git needs libcurl, libz, etc.)
- Installing files to correct locations
- Tracking what's installed
- Upgrading and removing packages</div>
<h3>Essential apt Commands</h3>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># === ALWAYS UPDATE FIRST ===</span>
$ sudo apt update <span class="comment"># refresh package lists (what's available)</span>
$ sudo apt upgrade <span class="comment"># upgrade all installed packages</span>
$ sudo apt full-upgrade <span class="comment"># upgrade + handle dependency changes</span>
<span class="comment"># === INSTALL ===</span>
$ sudo apt install git <span class="comment"># install a package</span>
$ sudo apt install git curl wget <span class="comment"># install multiple at once</span>
$ sudo apt install -y git <span class="comment"># auto-answer yes to prompts</span>
<span class="comment"># === REMOVE ===</span>
$ sudo apt remove firefox <span class="comment"># remove package (keeps config files)</span>
$ sudo apt purge firefox <span class="comment"># remove package + config files</span>
$ sudo apt autoremove <span class="comment"># remove unused dependencies</span>
<span class="comment"># === SEARCH ===</span>
$ apt search "text editor" <span class="comment"># search for packages</span>
$ apt show git <span class="comment"># show details about a package</span>
$ apt list --installed <span class="comment"># list all installed packages</span>
$ apt list --installed | grep python <span class="comment"># find installed python packages</span>
<span class="comment"># === INFO ===</span>
$ dpkg -L git <span class="comment"># list all files installed by a package</span>
$ dpkg -S /usr/bin/git <span class="comment"># which package owns this file?</span>
$ apt policy git <span class="comment"># show installed and available versions</span></code></pre>
<h3>Repositories (PPAs)</h3>
<p>Sometimes the version in the default repositories is old. You can add extra <strong>PPAs</strong> (Personal Package Archives) for newer or third-party software:</p>
<pre><code><span class="lang-label">Shell</span>
<span class="comment"># Add a PPA (example: newer version of something)</span>
$ sudo add-apt-repository ppa:some-ppa/name
$ sudo apt update
$ sudo apt install package-name
<span class="comment"># Remove a PPA</span>
$ sudo add-apt-repository --remove ppa:some-ppa/name</code></pre>