forked from UWCS/linux-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab.tex
284 lines (202 loc) · 11.3 KB
/
lab.tex
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
\documentclass[a4paper,11pt,parskip=half-]{scrartcl}
% Packages
\usepackage[english]{babel}
\usepackage{array}
\usepackage{amsmath}
\usepackage{ascii}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{graphicx}
\usepackage[a4paper,top=2cm,bottom=2cm,left=2cm,right=2cm,marginparwidth=1.75cm]{geometry}
\usepackage[defaultfam,tabular,lining]{montserrat}
\usepackage[T1]{fontenc}
\usepackage{wrapfig}
\usepackage{pmboxdraw}
\graphicspath{{images/}}
\pagestyle{empty}
\setkomafont{section}{\usefont{T1}{fvs}{b}{n}\Large}
\renewcommand*\oldstylenums[1]{{\fontfamily{Montserrat-TOsF}\selectfont #1}}
\renewcommand{\ttdefault}{pcr}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{wrapfigure}{r}{0.2\textwidth}
\vspace{-10pt} % Move shield in line with text
\includegraphics[width=0.9\linewidth]{shield.png}
\vspace{-100pt} % Prevent text below from moving out of the way
\end{wrapfigure}
\normalfont \Huge \bfseries UWCS Linux 101 Lab
\normalfont\LARGE A practical introduction to Linux
\normalsize
\section*{Logging In}
Before we start, you'll need to gain access to the department machines - the information needed for this should have been sent to your university email address.
If you have any issues logging in, let a lab tutor know!
They'll also be around to help if you get stuck.
Now that you've (hopefully) logged in, let's get started with the terminal!
\section*{Getting Around}
First, click the start button at the bottom-left corner of the screen. \\
Then, click the "terminal" menu item. You should see something like this:
\centering \includegraphics[width=0.9\textwidth]{terminal.png}
\raggedright
% explanation of what can be seen.
When opening the terminal, you'll be placed in your home directory - denoted by a $\sim$. \\
But what can you actually access from here? Let's use our first command to find out:
\Large \texttt{ls} \normalsize - Lists the contents of the directory you're currently in.
All you have to do is type \texttt{ls} and hit enter to execute the command.
What do you see?
For the moment, there should just be a few folders, also referred to as sub-directories.
If you want to find out what's inside, you need to be able to change directory:
\Large \texttt{cd <path>} \normalsize - Changes directory to the specified path.
Like most commands we will encounter from here on out, this one takes an argument, \texttt{path}.
This argument specifies exactly where we'd like to change directory to.
\centering
\begin{tabular}{l|c}
Example & Explanation \\
\hline
\Large \texttt{cd scripts} \normalfont & Change to the \texttt{scripts} folder in the current directory. \\
\Large \texttt{cd ..} \normalfont & Change to the parent directory (a level above the current one). \\
\Large \texttt{cd $\sim$} \normalfont & Change to the home directory (useful if you get lost).
\end{tabular}
\raggedright
You can also chain multiple directory moves together!
For example, moving a directory with \texttt{cd ..} then down with \texttt{cd scripts} could be combined into just \texttt{cd ../scripts}.
\bfseries Task 1: \normalfont
Before moving on, use the terminal to explore all the folders accessible from your home directory.
Make sure to list out all the contents - is there anything inside?
\newpage
By now, you have sadly realised the folders are empty.
So, let's aim to fix that.
\section*{Creation and Deletion}
In this section, we'll introduce commands to create and delete entities on the file system:
\Large \texttt{touch [<path>/]<name>} \normalsize \\
Creates a file with the given name in the specified directory (current if no path given).
Note: the square brackets denote that an argument is optional.
\texttt{mkdir} is used to create sub-directories in a similar way (replace \texttt{touch} with \texttt{mkdir}).
Files can be removed using the \texttt{rm} command (again, replace \texttt{touch}).
If we want to be able to remove folders, we can override the default behaviour using the \texttt{-r} (recursive) flag:
\Large \texttt{rm -r [<path>/]<name>} \normalsize \\
Removes the specified file or directory.
If non-empty, \bfseries all contents are deleted. \normalfont
Flags are optional arguments declared after the command name that add additional functionality.
To view a command's full list of arguments, you can type \texttt{man <command>}.
\bfseries Task 2: \normalfont
With all of this in mind, it’s time to make some files and folders!
We'll walk you through the process of replicating (then partially deleting) the folder structure below.
\begin{verbatim}
~
├── foo
│ └── bar.baz
└── public_html
├── css
│ └── app.css
└── index.html
\end{verbatim}
While in the home directory, we create the \texttt{foo} directory and it's \texttt{bar.baz} file:
\qquad \texttt{mkdir foo} \\
\qquad \texttt{touch foo/bar.baz}
To create the \texttt{public\_html} directory and its contents, a similar pattern is followed.
You might think to create both folders using \texttt{mkdir public\_html/css}, but this will fail, as \texttt{mkdir} requires all but the last part of the path to exist already.
We can override this behaviour with the \texttt{-p} flag, which creates intermediate directories when required.
From here, try creating \texttt{index.html} and \texttt{app.css} for yourself.
Finally, we’re going to remove the foo directory and its contents.
One of the ways you can do this is \texttt{rm -r foo}.
For a bonus challenge, see if you can delete the directory using the \texttt{rmdir} command instead!
\bfseries Task 3 (Optional): \normalfont
The new directory is a better place to practice the navigation commands discussed in the previous section.
If you forget where you are on the system, you can always type \texttt{pwd} to get the full path of your location.
Now that you feel more comfortable, let's make a little website...
\newpage
\section*{Editing Files}
When it comes to editing files, there's a variety of programs available to you.
And, just like a programmer's preferred distribution of Linux, it's a large point of contention among us!
For this lab, we'll be using Visual Studio Code to do this.
\bfseries Task 4: \normalfont
Using the \texttt{code <path>} command on a file/folder, open up the \texttt{index.html} file we created and insert some HTML for your site.
Here's a very basic example page:
\qquad \texttt{<!DOCTYPE html>} \\
\qquad \texttt{<html>} \\
\qquad \qquad \texttt{<head>} \\
\qquad \qquad \qquad \texttt{<title>Linux 101 Test Page</title>} \\
\qquad \qquad \texttt{</head>} \\
\qquad \qquad \texttt{<body>} \\
\qquad \qquad \qquad \texttt{<h1>Hello world!</h1>} \\
\qquad \qquad \qquad \texttt{<p>This is a test page</p>} \\
\qquad \qquad \texttt{</body>} \\
\qquad \texttt{</html>}
Once you've done this, you can find your shiny new webpage at:
\qquad \texttt{https://dcs.warwick.ac.uk/$\sim$u[your student id]}
...or at least you would, if you had the permissions to access it.
\section*{Changing Permissions}
\begin{verbatim}
[u1234567 ~]$ ls -l
-rw-rw-r-- 1 u1234567 dcsugrad 92194 Sep 16 19:37 aaaa.gif
drwx-wx--- 2 u1234567 dcsugrad 4096 Sep 16 19:36 cat_pictures
-rw-r----- 1 u1234567 dcsugrad 42 Sep 16 19:37 important.txt
\end{verbatim}
The \texttt{l} flag for the \texttt{ls} command is very useful, as it shows us detailed information on files and folders.
For example, we can see who owns it, the group it belongs to, the size in bytes, and when it was last modified.
But what we're interested in is the permissions.
They determine not only who can access what, but how:
\centering
\begin{tabular}{l|l|l}
Permission & Symbol & Meaning \\
\hline
Read & \texttt{r} & Can view the contents \\
Write & \texttt{w} & Can change the contents \\
Execute & \texttt{x} & Can run as a program.
\end{tabular}
\raggedright
Each of these permissions can be applied to three different types of users:
\centering
\begin{tabular}{l|l|l}
Types & Symbol & Meaning \\
\hline
User & \texttt{u} & The file owner \\
Group & \texttt{g} & The user group of the file \\
Other & \texttt{o} & Any other user
\end{tabular}
\raggedright
In short - the first character indicates if something is a directory, the next three represent user permissions, the next three group permissions, and the final three other users.
These permissions can be modified using the \texttt{chmod} command.
The syntax for using \texttt{chmod} is extensive, with two main ways to achieve the same goal.
The first explicitly states the permissions for each permission group, like so:
\qquad \texttt{chmod u=rwx,g=rx,o=r <file path>}
The second way uses an octal digit to represent each permission group:
\qquad \texttt{chmod 754 <file path>}
Each digit represents user, group and other permissions respectively.
These digits are calculated by taking 0, and adding values to it depending on wanted permissions. \\
+4 for read, +2 for write, and +1 for execute.
The \texttt{-R} option can be used to perform a recursive permission change.
This will modify all files and sub-directories in the directory you specify with your chosen permissions.
\bfseries Task 5: \normalfont
Fix the permissions for your web page.
For \texttt{index.html}, give the user read and write permissions, and let the other two permission groups read.
Everything else in the \texttt{public$\_$html} directory (including the directory itself) should be set to \texttt{rwx} for the user, and \texttt{rx} for the other two permission groups.
Make sure everything is correct afterwards.
Finally, you'll want to add execute permissions in the home directory itself. Type:
\qquad \texttt{chmod o+x .}
Now, time to see our public web page in all of its underwhelming glory! \\
This concludes the main part of the lab.
\section*{Bonus Tasks}
\bfseries B1: \normalfont
Execute these commands in the \texttt{public$\_$html} folder.
What do you think they do?
\begin{enumerate}
\item \large \texttt{cd --} \normalsize
\item \large \texttt{ls -lat > output.txt} \normalsize
\item \large \texttt{grep p index.html} \normalsize
\end{enumerate}
\bfseries B2: \normalfont
To help organise your work, try creating a \texttt{modules} directory.
You might also want to add sub-directories within it for the ones you're going to take, such as \texttt{cs118} and \texttt{cs126}.
\bfseries B3: \normalfont
Your web page works, but it might be a bit... lacking?
Try improving your website.
Feel free to add some HTML or CSS if you like.
You could make it look pretty... or make it look cursed.
\section*{What next?}
Thanks for taking part in the lab! Hopefully you found it useful, and sorry if you didn't...
We'd be happy to hear your feedback and suggestions.
Make sure to check out the department's in-depth systems guide that includes topics such as remote access.
This is available at \href{https://warwick.ac.uk/fac/sci/dcs/intranet/user_guide/}{\texttt{https://warwick.ac.uk/fac/sci/dcs/intranet/user$\_$guide/}}
If you're interested in joining the Computing society, or want to ask any other questions, we'd be happy to welcome you in our community - \href{https://go.uwcs.uk/links}{\texttt{https://go.uwcs.uk/links}}
See you around!
\end{document}