1- # Linux Shells — Notes (CLI, shells, and basic Bash scripting)
1+ ---
2+ type : resource-note
3+ status : done
4+ created : 2026-03-11
5+ updated : 2026-03-11
6+ tags : [security-writeup, tryhackme, linux, shell]
7+ source : TryHackMe - Linux Shells
8+ platform : tryhackme
9+ room : Linux Shells
10+ slug : linux-shells
11+ path : TryHackMe/00-foundations/command-line/linux-shells.md
12+ topic : 00-foundations
13+ domain : [foundations, linux]
14+ skills : [enum, logs, bash-scripting]
15+ artifacts : [concept-notes, cookbook]
16+ sanitized : true
17+ ---
18+
19+ # Linux Shells
220
321## Summary
422
@@ -12,9 +30,11 @@ A *shell* is the user-facing interface that mediates between you and the operati
1230
1331---
1432
15- ## Mental model
33+ ## Key Concepts
34+
35+ ### Mental model
1636
17- ### Shell vs CLI
37+ #### Shell vs CLI
1838
1939* ** Shell** : the * facilitator* between user and OS (broad concept). A GUI can be seen as a “shell” too.
2040* ** CLI** : one concrete interaction mode provided by a shell (typed commands, text IO).
@@ -27,17 +47,17 @@ User → Shell (CLI/GUI) → OS services (kernel + system calls) → hardw
2747
2848---
2949
30- ## Task 2 — Interacting with a shell (core commands)
50+ ### Task 2 — Interacting with a shell (core commands)
3151
32- ### 1) Where am I?
52+ #### 1) Where am I?
3353
3454``` bash
35551 pwd
3656```
3757
3858* Prints current working directory (CWD).
3959
40- ### 2) Move around
60+ #### 2) Move around
4161
4262``` bash
43631 cd < dir>
@@ -47,7 +67,7 @@ User → Shell (CLI/GUI) → OS services (kernel + system calls) → hardw
4767
4868* ` .. ` = parent directory, ` ~ ` = home.
4969
50- ### 3) What’s here?
70+ #### 3) What’s here?
5171
5272``` bash
53731 ls
@@ -56,7 +76,7 @@ User → Shell (CLI/GUI) → OS services (kernel + system calls) → hardw
5676
5777* ` -l ` long listing; ` -a ` includes dotfiles.
5878
59- ### 4) Read a file
79+ #### 4) Read a file
6080
6181``` bash
62821 cat < file>
@@ -65,7 +85,7 @@ User → Shell (CLI/GUI) → OS services (kernel + system calls) → hardw
6585
6686* Prefer ` less ` for large files.
6787
68- ### 5) Search inside a file
88+ #### 5) Search inside a file
6989
7090``` bash
71911 grep " PATTERN" < file>
@@ -83,21 +103,21 @@ User → Shell (CLI/GUI) → OS services (kernel + system calls) → hardw
83103
84104---
85105
86- ## Task 3 — Types of shells (bash / fish / zsh)
106+ ### Task 3 — Types of shells (bash / fish / zsh)
87107
88- ### Identify the current shell
108+ #### Identify the current shell
89109
90110``` bash
911111 echo " $SHELL "
92112```
93113
94- ### List installed shells
114+ #### List installed shells
95115
96116``` bash
971171 cat /etc/shells
98118```
99119
100- ### Switch shells (temporary)
120+ #### Switch shells (temporary)
101121
102122``` bash
1031231 zsh
@@ -106,15 +126,15 @@ User → Shell (CLI/GUI) → OS services (kernel + system calls) → hardw
106126
107127* This switch typically lasts for the session.
108128
109- ### Change default shell (persistent)
129+ #### Change default shell (persistent)
110130
111131``` bash
1121321 chsh -s /usr/bin/zsh
113133```
114134
115135* Requires logout/login (or a new terminal) to take effect.
116136
117- ### Feature summary (practical reading)
137+ #### Feature summary (practical reading)
118138
119139* ** Bash (Bourne Again Shell)**
120140
@@ -138,31 +158,31 @@ User → Shell (CLI/GUI) → OS services (kernel + system calls) → hardw
138158
139159---
140160
141- ## Task 4 — Shell scripting building blocks
161+ ### Task 4 — Shell scripting building blocks
142162
143- ### 1) Shebang
163+ #### 1) Shebang
144164
145165The first line tells the OS which interpreter should execute the script.
146166
147167``` bash
1481681 #! /bin/bash
149169```
150170
151- ### 2) Make script executable
171+ #### 2) Make script executable
152172
153173``` bash
1541741 chmod +x script.sh
155175```
156176
157- ### 3) Run a script in the current directory
177+ #### 3) Run a script in the current directory
158178
159179``` bash
1601801 ./script.sh
161181```
162182
163183* ` ./ ` matters because the current directory is usually ** not** in ` PATH ` .
164184
165- ### 4) Variables + input (` read ` )
185+ #### 4) Variables + input (` read ` )
166186
167187``` bash
1681881 #! /bin/bash
@@ -171,7 +191,7 @@ The first line tells the OS which interpreter should execute the script.
1711914 echo " Welcome, $name "
172192```
173193
174- ### 5) Loops
194+ #### 5) Loops
175195
176196``` bash
1771971 #! /bin/bash
@@ -180,7 +200,7 @@ The first line tells the OS which interpreter should execute the script.
1802004 done
181201```
182202
183- ### 6) Conditionals
203+ #### 6) Conditionals
184204
185205``` bash
1862061 #! /bin/bash
@@ -193,7 +213,7 @@ The first line tells the OS which interpreter should execute the script.
1932138 fi
194214```
195215
196- ### 7) Comments
216+ #### 7) Comments
197217
198218``` bash
1992191 # This is a comment. It is ignored by the interpreter.
@@ -207,15 +227,15 @@ The first line tells the OS which interpreter should execute the script.
207227
208228---
209229
210- ## Task 5 — “Locker script” pattern (variables + loop + conditional)
230+ ### Task 5 — “Locker script” pattern (variables + loop + conditional)
211231
212- ### What the script demonstrates
232+ #### What the script demonstrates
213233
214234* Collect multiple inputs using a loop.
215235* Validate all required fields using logical AND (` && ` ).
216236* Print “success” only when all conditions match.
217237
218- ### Readable refactor (same idea, more direct)
238+ #### Readable refactor (same idea, more direct)
219239
220240``` bash
2212411 #! /bin/bash
@@ -239,13 +259,13 @@ The first line tells the OS which interpreter should execute the script.
239259
240260---
241261
242- ## Task 6 — Practical exercise: scan logs for a keyword
262+ ### Task 6 — Practical exercise: scan logs for a keyword
243263
244- ### Goal
264+ #### Goal
245265
246266Search for a target keyword (e.g., ` thm-flag01-script ` ) across ` *.log ` files inside a directory (e.g., ` /var/log ` ).
247267
248- ### Script skeleton (robust version)
268+ #### Script skeleton (robust version)
249269
250270``` bash
2512711 #! /usr/bin/env bash
@@ -269,7 +289,7 @@ Search for a target keyword (e.g., `thm-flag01-script`) across `*.log` files ins
26928919 exit 1
270290```
271291
272- ### Common pitfalls
292+ #### Common pitfalls
273293
274294* ** Unquoted variables** : break on spaces or glob expansion.
275295* ** Accidental spaces in patterns** : ` grep "FLAG " ` ≠ ` grep "FLAG" ` .
@@ -278,7 +298,7 @@ Search for a target keyword (e.g., `thm-flag01-script`) across `*.log` files ins
278298
279299---
280300
281- ## Pitfalls & operational notes
301+ ### Pitfalls & operational notes
282302
283303* Prefer ` less ` over ` cat ` for large outputs.
284304* Prefer * exit codes* + ` grep -q ` for scripting logic.
@@ -287,7 +307,7 @@ Search for a target keyword (e.g., `thm-flag01-script`) across `*.log` files ins
287307
288308---
289309
290- ## Related tools
310+ ## Related Tools
291311
292312* ` less ` , ` head ` , ` tail -f ` (file viewing)
293313* ` find ` , ` xargs ` (file discovery pipelines)
@@ -296,7 +316,7 @@ Search for a target keyword (e.g., `thm-flag01-script`) across `*.log` files ins
296316
297317---
298318
299- ## Further reading
319+ ## Further Reading
300320
301321* Bash reference and scripting patterns
302322* Fish documentation (interactive features)
0 commit comments