-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlinux101.qmd
More file actions
2367 lines (1538 loc) · 81.2 KB
/
linux101.qmd
File metadata and controls
2367 lines (1538 loc) · 81.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
---
format:
revealjs:
self-contained: true
navigation-mode: linear
controls-layout: bottom-right
controls: false
footer: "[Research IT Website]({{< var rc.website >}}) | [Research IT Query]({{< var rc.servicedesk >}}) | [Courses Material]({{< var rc.linux101 >}}) | [Cheat sheet](#cheat-sheet)"
code: HPC 0
name: Introduction to Linux for HPC
---
{{< include _title.qmd >}}
# Introduction section
## Introduction to Linux
Aims of this training:
- Introduce you to using command line interface (CLI) Linux
- Build your confidence in navigating Linux file systems using the command line
- Enable you to use Linux without a graphical user interface (GUI)
- Prepare you for [HPC1: Introduction to High Performance Computing](https://arc.leeds.ac.uk/training/courses/hpc1/)
::: {.notes}
- This is a brief, introductory level session.
- Do not assume knowledge of file systems/directory structures/other computing background.
:::
## Format of this course
- This is a **2.5 hour tutorial**. We will be trying out what we are learning, so be ready for some typing!
- These lecture slides are based on the [Software Carpentries documentation on Unix Shell basics](https://swcarpentry.github.io/shell-novice/), but is a shorter course and uses different examples.
- Once you finish this tutorial, we recommend you read through the Software Carpentries material and follow through the tutorial there: you can do this work from the same *virtual machine* we will be using today.
::: {.notes}
- We include notes at the end on how to use our virtual machine to run the Software Carpentries material
:::
## Format of these slides {.smaller}
- Everything you need for this session is in these slides.
- We recommend you have a copy open on your computer.
- If you have enough room on your screen, have these notes and your command line side-by-side.
- These notes should also be viewable via mobile if you don't mind not being able to copy and paste!
- There is a quick reference [cheat sheet](#cheat-sheet) linked in the footer; you can return to your place in the slideshow from this cheat sheet using the back button.
::: {.notes}
- The cheat sheet can be used from any point in the tutorial; you can just click the back arrow
and return to the exact point in the slides
:::
## Syllabus
- Interacting with a computer: operating systems, GUIs and CLIs, bash
- File systems on Linux
- Navigating filesystems from the command line
- Creating and editing files and directories
- Running simple scripts
::: {.notes}
- If we don't manage to cover all these topics, you will be able to follow on at home.
:::
## Learning method {.smaller}
The aim *is not for you to leave knowing loads of Linux Bash commands*!
- There are many fantastically
useful commands we won't cover today (read through the [Software Carpentries course](https://swcarpentry.github.io/shell-novice/)
after this for some extra commands);
- The aim is for you to get a feel for how Linux's command line works,
to be able to problem solve and find the commands you need.
- This is an introductory course for complete beginners: of course, you're welcome here if you want a refresher, but expect for
the course to be slow-paced.
::: {.notes}
- Emphasise that the point is *not* to teach lots of shortcuts and commands.
- It's ok not to remember commands from today - the point is that if you want to do something on Linux,
you'll be better able to search for and then understand the answer.
:::
## PRIMM method {.smaller}
It's helpful for you as a learner to understand the PRIMM structure so you can apply it while working through this course. Not every step
will be relevant or used at every stage of the course!
::: {.panel-tabset}
### What's PRIMM?
PRIMM is a pedagogical method specifically aimed at teaching text-based programming. While research into adult programming
learners is very limited (especially in terms of demographics; many key studies that are cited have overwhelmingly homogenous test groups),
the PRIMM method has a few key benefits:
- It supports learners with different ability levels and who learn at different speeds;
- It can be applied by learners even if the course materials are not specifically built with it in mind;
- It can be applied to asynchronous learning materials (for example, if you are using these notes online on your own).
### P
The **P** in PRIMM stands for **predict**:
When you first see a command, script, or piece of code, before running it, predict what you think it will
do. It's ok to get this wrong: the important thing is to get into the habit of predicting! This
helps to keep you actively engaged and focused, and begins to build an intuitive sense about the structure of commands.
- What do you think the code is going to do generally?
- What do you think the output in your terminal is going to look like?
### R
The **R** in PRIMM stands for **run**:
- Run the code or program;
- How does the output/effect compare to your prediction?
- What did you get right?
- What did you misinterpret?
- Do you understand what happened?
### I
The **I** in PRIMM stands for **investigate**:
Let's dig a little deeper into the *structure* of code you've used.
- What options or arguments did you use, and what effect did they have?
- Can you find some documentation on the command you used?
- Does the description match how you would describe the code?
- If no, why does your understanding of it diverge?
- What other options or features are available?
### M
The first **M** in PRIMM stands for **modify**:
- Try running the code with different options:
- Change only a small thing at a time;
- Always predict what you think the output will be!
- Compare the actual output with your prediction;
- Compare your understanding to the available documentation.
This stage helps you to gradually increase the difficultly of the tasks you are doing!
### M
The second **M** in PRIMM stands for **make**:
This stage is about making the code your own.
- At this stage, you can try implementing snippets of code you've already learned, but to solve a new or different problem;
- Again, use the previous stages when you are writing your code: *predict* what you think will happen, *run* the code and compare
the output to your predictions, and *investigate* the structure of it, especially if it does not behave how you intended!
### Key notes
**Read before you write** - research has proven repeatedly the importance of reading and predicting the output of code as
a method of learning, over just *getting straight into it* and writing code.
- Novice programmers need to acquire accuracy in tracing code *before* they can program independently
- Trying to write code first leads to frustration and confusion
**Learn in a way that suits you** - if that is copying and pasting commands
from the slides instead of trying to keep up with typing, *that's ok!*
:::
# Ways of interacting with a computer
::: {.notes}
- Our first section is going to cover some very high-level concepts about how we use computers
:::
## Interacting with a computer {.smaller}
When we use a computer, we interact with the hardware through an **operating system** or **OS**.
Common operating systems for research computers include:
- Microsoft Windows
- MacOS
- Linux
We are going to be looking at Linux today, which is a family of operating systems that are **Open Source** and are widely used in research, for example on **High Performance Computing** platforms like ARC4 or Aire.
## Interacting with a computer {.smaller}
When we use a computer, like our desktop or laptop, we often use a **Graphical User Interface** or a **GUI**.
- GUIs allow us to interact with a computer through graphical means: icons, text, buttons, windows. GUIs usually involve using a mouse and clicking into menus.
- The Windows desktop and MacOS desktop are GUIs that let you control the computer graphically.
- Many computer programs also have GUIs: for example, Excel.
{fig-align="center" fig-alt="A screenshot of Excel."}
::: {.notes}
- What are some of the benefits of GUIs? See if people have suggestions.
- What are some of the downsides of using GUIs?
:::
## Interacting with a computer {.smaller}
As well as using a GUI, we can also interact with computers using a **Command Line Interface** or a **CLI**.
- CLIs allow us to interact with a computer through text-based commands typed into the command-line.
- While GUIs can be simple and intuitive to use, they can make it difficult to reproduce workflows:
- Sometimes you have to record by hand (or with a screen recording) what sub-options from different menus you used;
- Updates to GUIs can make it difficult to find the same menu options;
- A workflow with multiple steps can be tedious to repeat for multiple datasets (having to click through multiple layers of menu options for each dataset).
- Many large research machines (such as the HPC machines ARC4 and Aire here at Leeds) *do not have a GUI* and so you need to interact with them through a **CLI**.
## Command Line Interfaces {.smaller}
- There are multiple different CLIs available:
- General-purpose CLIs are available for each **Operating System** for general computer control:
- Windows Command Prompt;
- Windows Powershell;
- Mac Terminal;
- Some specific programs have their own custom CLIs:
- Anaconda Prompt for Windows;
- Git Bash for Windows;
- Today, we are going to be using a **Unix Shell**:
- This is the general-purpose CLI that underpins both Linux and Mac;
- We will use Bash, a popular Unix Shell.
::: {.notes}
- Essentially, there are many different ways to access a command line, and there are different types
of command line interfaces!
- We are teaching you one today that is easy to access, and is used on research HPC systems
:::
## Poll
Throughout this presentation, we will be using quick polls to gauge your familiarity with concepts.
Let's test it out:
[Click here to go to Poll](https://universityofleeds.display.vevox.com#/present/696636/ULXGUZROA4XT20VKGCAZ){target="_blank"}
::: {.notes}
- Open up vevox session and activate relevant poll
:::
## Bash {.smaller}
How do we access Bash?
- Bash is the default shell on Unix systems like Linux or Mac
- Bash is also available through many command-line tools for Windows:
- Git Bash for Windows
- Anaconda Prompt
We're going to use a **virtual machine** for this course: this is a Linux machine running in the cloud.
This means that everyone here can run it with the exact same set-up; you only need a browser.
# Linux filesystems
::: {.notes}
- Before we open up our virtual machine, we are going to talk a little bit about how Linux filesystems work.
- It's important for us to build a little bit of a mental map before we start using the command line,
just to make it less confusing.
- This might seem familiar, if you're used to navigating filesystems on Windows or Mac already!
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
```
Each rectangle is a folder or **directory** (**dir** for short)
::: {.notes}
- This shows a sketch of a file system.
- We have a hierarchy of folders or directories sitting inside one another.
- Folders are usually called "directories" on Linux systems, but they mean the same thing.
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
style / fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
Each rectangle is a folder or **directory** (**dir** for short)
::: {.notes}
- This branching system starts from the root (the forward slash) at the very top, highlighted in pink.
- Inside this root directory, we have a bunch of system folders - we don't need to worry about these now.
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
Each rectangle is a folder or **directory** (**dir** for short)
::: {.notes}
- One of the directories is called "home": this contains all the home directories of users.
- The home directories are usually called after their owner's username.
- If you look in this directory on a personal or family computer, you might find a handful of user home directories
- If you look at this directory on a university HPC system, like Aire, you'll find hundreds of user home directories
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
style my-username fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
The `my-username` folder is your **user home directory**
::: {.notes}
- Confusingly, we refer to this highlighted directory as your *home* directory
- Even though there is a folder one level up that is called home!
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
style my-username fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
How do we describe the address of this home directory?
::: {.notes}
- How do we describe where this directory or folder is?
- We describe it in a similar way to a website URL, using it's path
- We need to know all the folders directly above it.
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
style my-username fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style / fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
The folders in the address are `/`, `home` and `my-username`
::: {.notes}
- Above our username directory, we have home and the root (which is denoted by just a forward slash)
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
style my-username fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style / fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
Stick them together like a URL: `/home/my-username`
::: {.notes}
- We just have to put them together like a web address (because the internet is basically just a giant file structure)
:::
## File system on Linux
On Windows, file paths use backlashes ( `\` ) instead of forward slashes (`/`)!
- This can cause confusion and errors if you are writing scripts that load in data from certain file paths, and need to use both Windows and Linux!
- Thankfully there are lots of ways around this, including libraries for handling paths in Python and R
::: {.notes}
- It's useful to note that Windows uses slashes in the opposite direction for file paths.
- We're not going to focus on this today as we are using only Linux
- But if you get an error while coding it's useful to keep this in mind.
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--obin
/ o--odev
/ o--oetc
/ o--ohome
home o--omy-username
home o--omy-friend
/ o--otmp
my-username o--o all_my_files
style my-username fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style / fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
Stick them together like a URL: `/home/my-username`
::: {.notes}
- Back to our file system.
- Today, everything we are doing will be in our home directory, so let's just focus on that!
- When you log in to a linux system, this is usually where you will be dropped!
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--ohome
home o--omy-username
my-username o--o all_my_files
style my-username fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style / fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
`/home/my-username/all_my_files` is a bit long...
::: {.notes}
- Typing the full path to our files and folders is a bit tedious
- lets look at a shorter way
:::
## File system on Linux
::: {layout-ncol=2}
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
/ o--ohome
home o--omy-username
my-username o--o all_my_files
style my-username fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
style / fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
home["~"] o--o all_my_files
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
:::
`/home/my-username/all_my_files` is a bit long...
::: {.notes}
- Typing the full path to our files and folders is a bit tedious
- lets look at a shorter way
:::
## File system on Linux
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '32px', 'padding': '40px'}}}%%
flowchart
home["~"] o--o all_my_files
style home fill:#f9f,stroke:#333,stroke-width:10px,color:#333
```
- To save us from typing out `/home/my-username` every time we refer to a directory or file, we can use the shortcut `~`, called a *tilde*
- This turns `/home/my-username/all_my_files` to `~/all_my_files`
## Poll
Let's test your familiarity with Linux file paths!
[Click here to go to Poll](https://universityofleeds.display.vevox.com#/present/696636/ULXGUZROA4XT20VKGCAZ){target="_blank"}
## Let's explore some files!
Time to explore some files on a Linux system!
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '28px'}}}%%
flowchart TD
A["/home/vscode/ <br> or ~"] o--o B[red-folder]
A o--o C[pink-folder]
A o--o D[blue-folder]
B o--o r1([red-1.txt ])
B o--o r2([red-2.txt ])
B o--o r3([red-3.txt ])
C o--o P1[pink-sub-folder]
C o--o p2(["pink-file.md <br>"])
C o--o p3{{"say_hi.sh <br>"}}
P1 o--o p4(["**helloworld.py** <br>"])
P1 o--o p5(["pink-data.csv <br>"])
D o--o b1(["**blue.r** <br>"])
```
# First steps in bash
## Using our custom virtual machine {.smaller}
For this course, we've built a custom virtual machine for you to use.
This requires a **GitHub** account which you were asked to set up before this course.
(Don't worry if you haven't - please go and quickly sign up to [GitHub](https://github.com/signup) now!)
- There are many other ways to access the bash shell, such as on one of the HPC systems here at Leeds, or by installing [git bash](https://git-scm.com/downloads/win) on Windows, or using the terminal on Linux or Mac.
- We want everyone in the class to have the same directory structure and environment which is why we are using a virtual machine!
## Launch virtual machine
::::: {.panel-tabset}
### Step 1
One of the pre-requisites for this course was signing up for an account with GitHub,
as this is the service we use to host the virtual Linux machines for teaching this session.
[Log in to GitHub now (or sign up if you haven't already).](https://github.com/)
### Step 2
[Follow this link to open the course repository.](https://github.com/ARCTraining/linux-101)
### Step 3
There will be a green button with the word "Code", which will then bring up a menu when clicked.
:::: {layout="[ 30, 70 ]"}
::: {#first-column}
{fig-align="center" fig-alt="A green button with the word 'Code'."}
↑ [Click this button,]{style="font-size: 0.95em;"}
[this menu opens ]{style="font-size: 0.95em;"} →
:::
::: {#second-column}
{fig-align="center" fig-alt="A green button with the word 'Code'."}
:::
::::
:::::
## The terminal
Once you've launched your virtual machine, you will see a terminal window something like this:
::: {style="font-size: 0.7em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/workspaces/bash-codespaces-template]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$ ▮]{style="color: white"}
[_ ]{style="color: black"}
:::
:::::{.fragment .fade-in}
::: {style="font-size: 0.7em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [<u>/workspaces/bash-codespaces-template</u>]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$ ▮]{style="color: white"}
[_ ]{style="color: black"}
:::
The <u>underlined section</u> is your directory *path*.
:::::
## The terminal
Once you've launched your virtual machine, you will see a terminal window something like this:
::: {style="font-size: 0.7em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/workspaces/bash-codespaces-template]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$ ▮]{style="color: white"}
[_ ]{style="color: black"}
:::
:::::{.fragment .fade-in}
::: {style="font-size: 0.7em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/workspaces/bash-codespaces-template]{style="color: #00FFFF"} [<u>(main)</u>]{style="color: #FF7F50"} [$ ▮]{style="color: white"}
[_ ]{style="color: black"}
:::
The <u>underlined section</u> has to do with the **git version control system**: not a topic for today, but you can learn about this in SWD2!
:::::
## The terminal
Once you've launched your virtual machine, you will see a terminal window something like this:
::: {style="font-size: 0.7em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/workspaces/bash-codespaces-template]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$ ▮]{style="color: white"}
[_ ]{style="color: black"}
:::
:::::{.fragment .fade-in}
::: {style="font-size: 0.7em"}
The dollar symbol ($) and rectangle (▮) on the right hand side are the end of the prompt and the cursor.
- The $ tells you where the computer's message ends, and where you can enter your commands.
- The ▮ (which will probably be slowly flashing) tells you where the cursor is; this often looks more like a vertical line ( | ) in other programs like Word.
:::
:::::
## The terminal
If you click on the [▮]{style="color: white; background-color: black"} or the space just to the right of the [$]{style="color: white; background-color: black"} you can type in your message:
::: {style="font-size: 0.7em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/workspaces/bash-codespaces-template]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$ hello▮]{style="color: white"}
[_ ]{style="color: black"}
:::
Anything you type will be in **white** text in the terminal; the cursor will blink at the end of the text.
To *send* the argument or message, you need to press ENTER on your keyboard.
## The terminal
If you click on the [▮]{style="color: white; background-color: black"} or the space just to the right of the [$]{style="color: white; background-color: black"} you can type in your message:
::: {style="font-size: 0.7em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/folders]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$]{style="color: grey"} [**this is the code you type**]{style="color: white"} [↵]{style="color: #DDA0DD; font-size: 1.5em;"}
[_ ]{style="color: black"}
:::
- The code you need to type/copy and paste is shown in **bold** white
- We will hide the cursor and fade the prompt ($) to grey
- We will show an ENTER symbol in pink to remind you how to enter the command (↵)
## Very first command: `cd`
We're going to use the `cd` command to bring us to our home directory.
::::: {style="font-size: 1.2em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/folders]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$]{style="color: grey"} [▮]{style="color: white"}
:::{.fragment .fade-in}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [/folders]{style="color: #00FFFF"} [(main)]{style="color: #FF7F50"} [$]{style="color: grey"} [**cd**]{style="color: white"} [↵]{style="color: #DDA0DD; font-size: 1.5em;"}
:::
:::{.fragment .fade-in}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [▮]{style="color: white"}
:::
[_ ]{style="color: black"}
:::::
## Very first command: `cd`
- `cd` stands for *change directory*
- It brings us back to our *home directory*, `~` or `/home/vscode`
:::{.fragment .fade-in}
- Our virtual machine is a little bit weird because it starts us off in a different folder: on most Linux systems, when you log in, you will immediately be in your home directory
:::
::::: {style="font-size: 1.2em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [▮]{style="color: white"}
:::::
## What's in this folder?
Now that you know how to find home (from wherever in the file system you are), you need to know what's *in* your home directory.
- You can *list* out the files and folders in your directory with the command `ls`
## What's in this folder? `ls` to list
Using the `ls` command to list out the contents of the directory:
::::: {style="font-size: 1.2em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [▮]{style="color: white"}
:::{.fragment .fade-in}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [**ls**]{style="color: white"} [↵]{style="color: #DDA0DD; font-size: 1.5em;"}
:::
:::{.fragment .fade-in}
[_ ]{style="color: black"}[blue-folder pink-folder red-folder]{style="color: #00FFFF"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [▮]{style="color: white"}
:::
[_ ]{style="color: black"}
:::::
## What's in this folder? `ls` to list
How do we know if `blue-folder` is a file or a directory? (imagine it has a less descriptive name)
::::: {style="font-size: 1.2em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [**ls**]{style="color: white"} [↵]{style="color: #DDA0DD; font-size: 1.5em;"}
[_ ]{style="color: black"}[blue-folder pink-folder red-folder]{style="color: #00FFFF"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [▮]{style="color: white"}
:::{.fragment .fade-in}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [**ls -F**]{style="color: white"} [↵]{style="color: #DDA0DD; font-size: 1.5em;"}
:::
:::::
## What's in this folder? `ls` to list
We can use `ls -F`: this tells us the category of the "things" in the directory
- If the name ends in a trailing forward slash (like `this/`) then the item is a directory or folder
::::: {style="font-size: 1.2em; text-align: left; background-color: black; color: white; font-family: monospace"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [**ls -F**]{style="color: white"} [↵]{style="color: #DDA0DD; font-size: 1.5em;"}
[_ ]{style="color: black"}[blue-folder/ pink-folder/ red-folder/]{style="color: #00FFFF"}
[_ ]{style="color: black"}[\@username]{style="color: #00FF00"} **→** [~]{style="color: #00FFFF"} [$]{style="color: grey"} [▮]{style="color: white"}
:::::
## What's in this folder? `ls` to list
This is what we expected: we saw in our directory map that we have three directories in our home (`~`): `red-folder`, `pink-folder`, and `blue-folder`.
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '28px'}}}%%
flowchart TD
A["/home/vscode/ <br> or ~"] o--o B[red-folder]
A o--o C[pink-folder]
A o--o D[blue-folder]
B o--o r1([red-1.txt ])
B o--o r2([red-2.txt ])
B o--o r3([red-3.txt ])
C o--o P1[pink-sub-folder]
C o--o p2(["pink-file.md <br>"])
C o--o p3{{"say_hi.sh <br>"}}
P1 o--o p4(["**helloworld.py** <br>"])
P1 o--o p5(["pink-data.csv <br>"])
D o--o b1(["**blue.r** <br>"])
```
## What's in this folder? `ls` to list
Let's list what's inside `pink-folder`...
```{mermaid}
%%| fig-align: center
%%| fig-width: 100%
---
config:
look: handDrawn
---
%%{init: {'themeVariables': { 'fontSize': '28px'}}}%%
flowchart TD
A["/home/vscode/ <br> or ~"] o--o B[red-folder]