-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstAss.html
405 lines (330 loc) · 15.7 KB
/
firstAss.html
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
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>
<title>Assignment 1. Getting to know your system</title>
</head>
<body>
<h1>Assignment 1. Getting to know your system</h1>
<p><small>[<a href='../index.html'>35L home</a> > <a href='../assign.html'>assignments</a>]</small></p>
<h2>Laboratory: Linux and Emacs scavenger hunt</h2>
<!-- diff,在UNIX系統上的一個工具程式,它可以比較兩個檔案之間的不同。通常它被用來比較同一個檔案,在不同版本間的差異。它可以產生一個擴展名為.diff或.patch的檔案,這個檔案可以被另一個工具程式patch來使用。-->
<p>Instructions: Do this assignment on the SEASnet GNU/Linux servers
<samp>lnxsrv06</samp>, <samp>lnxsrv07</samp>,
<samp>lnxsrv09</samp>, or <samp>lnxsrv10</samp>,
with <samp>/usr/local/cs/bin</samp>
prepended to your <samp>PATH</samp>.
Use the commands that you learned in class to find
answers to these questions. Don't use a search engine like Google, and
don't ask your neighbor, don't use GitHub, etc.
If you need a hint, ask the <abbr>TA</abbr>.
When you find a new command, run it so you can see exactly how it
works. In addition to turning in the answers to these questions, turn
in a description of your session discovering them.
</p>
<p>
As you do actions, use Emacs to record your keystrokes and each answer
in plain-text files <samp>key1.txt</samp> and <samp>ans1.txt</samp>
that you will submit as part of the assignment. If you prefer, you can
record and submit
<a href='https://orgmode.org/'>Org</a> files
<samp>key1.org</samp> and <samp>ans1.org</samp> instead
of <samp>.txt</samp> files;
see <a href='https://orgmode.org/worg/'>Hello Worg</a> for Org
introductions and tutorials.
</p>
<ol>
<li>
What shell command uses the <samp>man</samp> program
to print all the commands that have a specific
word in their man page (or at least the description part of the
man page)? (hint: <samp>man man</samp>)</li>
<li>
Where are the <samp>mv</samp> and <samp>sh</samp> programs
located in the file system?
List any shell commands you used to answer this question.</li>
<li>
What executable programs have names that are exactly two characters
long and end in <samp>r</samp>,
and what do they do?
List any shell commands you used to answer this question.</li>
<li>
When you execute the command named by the symbolic
link <samp>/usr/bin/emacs</samp>, which file actually is
executed?
List any shell commands you used to answer this question.</li>
<li>
What is the version number of the <samp>/usr/bin/gcc</samp> program?
of the plain <samp>gcc</samp> program? Why are they different programs?
<li>
The <samp>chmod</samp> program changes permissions on a file. What
does the symbolic mode <samp>u+sx,o-w</samp> mean, in terms of permissions?</li>
<li>
Use the <samp>find</samp> command to find all directories modified in
the last four weeks that are located under (or are the same as) the
directory <samp>/usr/local/cs</samp>.
List any shell commands you used to answer this question.</li>
<li>
Of the files in the same directory as <samp>find</samp>, how many of
them are symbolic links?
List any shell commands you used to answer this question.</li>
<li>
What is the oldest regular file in the <samp>/usr/lib64</samp>
directory? Use the last-modified time to determine age. Specify the
name of the file without the <samp>/usr/lib64/</samp> prefix. Consider
files whose names start with "<samp>.</samp>". List any shell
commands you used to answer this question.</li>
<li>
Where does the <samp>locale</samp> command get its data from?
List any shell commands you used to answer this question.</li>
<li>
In Emacs, what commands have <samp>downcase</samp> in their name?
List any Emacs commands you used to answer this question.</li>
<li>
Briefly, what do the Emacs keystrokes <samp>C-M-r</samp>
through <samp>C-M-v</samp> do? Can you list their actions
concisely?
List any Emacs commands you used to answer this question.</li>
<li>
In more detail, what does the Emacs keystroke <samp>C-g</samp> do?
List any Emacs commands you used to answer this question.</li>
<li>
What does the Emacs <samp>yank</samp> function do, and how
can you easily invoke it using keystrokes?
List any Emacs commands you used to answer this question.</li>
<li>
When looking at the directory <samp>/usr/bin</samp>, what's the
difference between the output of the <samp>ls -l</samp> command,
and the directory listing of the Emacs <samp>dired</samp> command?
List any shell or Emacs commands you used to answer this question.</li>
</ol>
<h2>Homework: Learning to use Emacs</h2>
<!-- DELETE-ME DELETE-ME DELETE-ME -->
<ul>
<li>Keith Waclena, <a
href='http://www2.lib.uchicago.edu/keith/tcl-course/emacs-tutorial.html'>A
Tutorial Introduction to GNU Emacs</a> (2009)</li>
<li><a
href='https://www.gnu.org/software/emacs/manual/emacs.html'>The
Emacs editor</a>, version 26.1 (2018)</li>
<li><a
href='https://www.gnu.org/software/emacs/manual/eintr.html'>An
Introduction to Programming in Emacs Lisp</a>, version 26.1 (2018)</li>
</ul>
<p>
For all the exercises, record the steps taken to accomplish the given tasks.
Use intelligent ways of answering the questions. For example, if
asked to move to the first occurrence of the word "scrumptious", do not
merely use cursor keys to move the cursor by hand; instead, use the
builtin search capabilities to find "scrumptious" quickly.
</p>
<p>
To start, download a copy of the web page you're looking at into a
file named <samp>assign1.html</samp>. You can do this
with <a href='https://www.gnu.org/software/wget/'>Wget</a>
or <a href='https://curl.haxx.se/'>curl</a>.
Use <samp><a href='http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html'>cp</a></samp>
to make three copies of this file. Call the copies
<samp>exer1.html</samp>, <samp>exer2.html</samp>, and <samp>exer3.html</samp>.
</p>
<h3>Exercise 1.1: Moving around in Emacs</h3>
<ol>
<li>Use Emacs to edit the file <samp>exer1.html</samp>.</li>
<li>Move the cursor to just after the first occurrence of the word "HTML" (all upper-case).</li>
<li>Now move the cursor to the start of the first later occurrence of the word "scavenger".</li>
<li>Now move the cursor to the start of the first later occurrence of the word "self-referential".</li>
<li>Now move the cursor to the start of the first later occurrence of the word "arrow".</li>
<li>Now move the cursor to the end of the current line.</li>
<li>Now move the cursor to the beginning of the current line.</li>
<li>
Doing the above tasks with the arrow keys takes many keystrokes, or it
involves holding down keys for a long time. Can you think of a way to
do it with fewer keystrokes by using some of the commands available in
Emacs?
<li>Did you move the cursor using the arrow keys? If so, repeat the
above steps, without using the arrow keys.</li>
<li>When you are done, exit Emacs.</li>
</ol>
<h3>Exercise 1.2: Deleting text in Emacs</h3>
<ol>
<li>Use Emacs to edit the file <samp>exer2.html</samp>. The idea is to
delete its HTML comments; the resulting page should display the same
text as the original.</li>
<li>Delete the 18th line, which is an HTML comment. <samp><!-- HTML comments look like this. --></samp></li>
<li>Delete the HTML comment containing the text
"<samp>DELETE-ME DELETE-ME DELETE-ME</samp>".</li>
<li>Delete the HTML comment containing the text "<samp>https://en.wikipedia.org/wiki/HTML_comment#Comments</samp>".</li>
<li>There are three more HTML comments; delete them too.</li>
</ol>
<p>
Once again, try to accomplish the tasks using a small number of keystrokes.
When you are done, save the file and exit back to the command line. You can
check your work by using a browser to view <samp>exer2.html</samp>. Also,
check that you haven't deleted something that you want to keep, by using
the following command:</p>
<pre><samp><a href='https://www.gnu.org/software/diffutils/'>diff</a> -u exer1.html exer2.html >exer2.diff
</samp></pre>
<p>The output file <samp>exer2.diff</samp> should describe only text
that you wanted to remove. Don't remove <samp>exer2.diff</samp>;
you'll need it later.</p>
<h3>Exercise 1.3: Inserting text in Emacs</h3>
<ol>
<li>Use Emacs to edit the file <samp>exer3.html</samp>.</li>
<li>Change the first two instances of "Assignment 1" to "Assignment 42".</li>
<li>Change the first instance of "UTF-8" to "US-ASCII".</li>
<li>Ooops! The file is not ASCII so you need to fix that. Remove every
line containing a non-ASCII character. You can find the next
non-ASCII character by searching for the regular
expression <samp>[^[:ascii:]]</samp>.
<li>Insert an empty line after the first line containing
"<samp></ol></samp>".</li>
<li>When you finish, save the text file and exit Emacs. As before,
use the <samp>diff</samp> command to check your work.</li>
</ol>
<h3>Exercise 1.4: Other editing tasks in Emacs</h3>
<p>
In addition to inserting and deleting text, there are other common tasks
that you should know, like copy and paste, search and replace, and undo.
</p>
<ol>
<li>Execute the command "<samp>cat exer2.html exer2.diff >exer4.html</samp>"
to create a file <samp>exer4.html</samp> that contains a copy of <samp>exer2.html</samp> followed by a copy of <samp>exer2.diff</samp>.</li>
<li>Use Emacs to edit the file <samp>exer4.html</samp>.
The idea is to edit the file so that it looks identical
to <samp>exer1.html</samp> on a browser, but the file itself is a
little bit different internally.</li>
<li>Go to the end of the file. Copy the new lines in the last chunk
of diff output, and paste them into the correct location earlier in the file.</li>
<li>Repeat the process, until the earlier part of the file is identical
to what was in the original.</li>
<li>Delete the last part of the file, which contains the diff output.</li>
<li>… except we didn't really want to do that, so undo the deletion.</li>
<li>Turn the diff output into a comment, by surrounding it with
"<samp><!--</samp>" and "<samp>--></samp>".
<li>Now let's try some search and replaces.
Search the text document for the pattern "<samp><ol></samp>".
How many instances did you find?
Use the search and
replace function to replace them all with the final-caps
equivalent "<samp><oL></samp>".</li>
<li>Check your work with viewing <samp>exer4.html</samp> with an HTML
browser, and by running the shell command "<samp>diff -u
exer1.html exer4.html >exer4.diff</samp>". The only differences
should be changes from "<samp><ol></samp>" to "<samp><oL></samp>",
and a long HTML comment at the end.</li>
</ol>
<h3>Exercise 1.5: Doing commands in Emacs</h3>
<p>
Do these tasks all within Emacs. Don't use a shell subcommand
if you can avoid it.</p>
<ol>
<li>Create a new directory named "<samp>junk</samp>" that's right under
your home directory.</li>
<li>In that directory, create a C source file <samp>hello.c</samp>
that contains the following text. Take care to get the text exactly
right, with no trailing spaces or empty lines, with the
initial <samp>#</samp> in the leftmost column of the first line, and
with all other lines indented to match exactly as shown:
<pre><samp>#include <stdio.h>
int
main (void)
{
char n = '\n', b = '\\', q = '"';
char const *p = "#include <stdio.h>%cint%cmain (void)%c{%c char n = '%cn', b = '%c%c', q = '%c';%c char const *p = %c%s%c;%c printf (p, n, n, n, n, b, b, b, q, n, q, p, q, n, n, n, n);%c return 0;%c}%c";
printf (p, n, n, n, n, b, b, b, q, n, q, p, q, n, n, n, n);
return 0;
}
</samp></pre>
</li>
<li>Compile this file, using the Emacs <samp>M-x compile</samp> command.
</li>
<li>Run the compiled program, and put its output into a new Emacs
buffer named <samp>hello-out</samp>.</li>
<li>Copy this buffer's contents directly into the log that you're
maintaining for this exercise. (You <em>are</em> using Emacs to
maintain the log, aren't you?)</li>
</ol>
<h3>Exercise 1.6: Running Elisp code</h3>
<ol>
<li>Visit Emacs's <samp>*scratch*</samp> buffer.</li>
<li>In the buffer, seed the random number generator with your student
ID as a string, dashes included. For example, if your student ID is
123-456-789, evaluate <samp>(random
"123-456-789")</samp>. Use <samp>C-j</samp>
(<samp>eval-print-last-sexp</samp>) to evaluate the expression,
and record the result that you get.</li>
<li>In the buffer, assign two random integers to the global
variables <samp>x</samp> and <samp>y</samp>. Start by
executing <samp>(setq x (random))</samp>. Again,
use <samp>C-j</samp>.</li>
<li>What is the product of the two variables? You can find this out
by evaluating <samp>(* x y)</samp>. What do you observe about the
result? If the answer is the correct mathematical answer,
keep trying again with a different pair of random integers
until you get an answer that is not mathematically correct.</li>
<li>Try evaluating <samp>(* x y)</samp> again, but this time with
<samp>M-:</samp> (<samp>eval-expression</samp>). What difference do you observe
in the output?</li>
<li>Are the two random integers truly random in the mathematical
sense? If not, what's not random about them?</li>
<li>Assuming <samp>(random)</samp> is truly random, what is the
probability that the two-variable product mentioned above is
mathematically incorrect? Explain how you calculated this.</li>
</ol>
<h2>Submit</h2>
<!-- You can learn more about HTML comments at
<https://en.wikipedia.org/wiki/HTML_comment#Comments>.
-->
<p>Submit the following two files, in either plain-text or Org format
(your choice).</p>
<dl>
<dt><samp>key1.txt</samp> or <samp>key1.org</samp></dt><dd>For
each homework exercise, the set
of keystrokes needed to do the exercise. Attempt to use as few
keystrokes as possible. Do not bother to write down the keystrokes
needed to start the editor (e.g., "<samp>e m a c s SP e x e r 1 . h t m
l Enter</samp>") or to type in the complicated C program of Exercise
1.5. Write down the label of the key for each keystroke, e.g.,
"<samp>a</samp>", "<samp>A</samp>" (if you type "<samp>a</samp>" while
holding down the shift key), "<samp>Tab</samp>", "<samp>Enter</samp>",
"<samp>Esc</samp>". Use "<samp>SP</samp>" for space. Use prefix
"<samp>C-</samp>" and "<samp>M-</samp>" for control
and meta characters: e.g., "<samp>C-f</samp>" represents Control-F,
and "<samp>M-f</samp>" represents Meta-F. Put a space or a newline
between each pair
of keystroke representations. For example: "<samp>e m a c s < v i
Backspace Backspace Backspace > v i</samp>". If you use some key not
described above, invent your own ASCII name for the key and explain
what key you mean, but don't put spaces or newlines in your key name.</dd>
<dt><samp>ans1.txt</samp> or <samp>ans1.org</samp></dt><dd>Answers
to each lab question.</dd>
</dl>
<p>The files should be ASCII text files with no control characters
other
than <a href='https://en.wikipedia.org/wiki/Horizontal_tab'>tab</a>
and <a href='https://en.wikipedia.org/wiki/Newline'>newline</a> (in
particular, the files should not
contain <a href='https://en.wikipedia.org/wiki/Carriage_return'>carriage
returns</a>). The shell
commands:</p>
<pre><samp><a href='http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_02'>LC_ALL=C</a> <a href='https://en.wikipedia.org/wiki/AWK'>awk</a> '/[^\t\f -~]/' key1.org ans1.org #</samp> <em>(if you submit .org files)</em>
<samp>LC_ALL=C awk '/[^\t\f -~]/' key1.txt ans1.txt #</samp> <em>(if you submit .txt files)</em>
</pre>
<p>should output nothing<!---->.</p>
<!--
<p>Or maybe more lines, if something has gone wrong.</p>
-<->-
-->
<hr>
<address>
© 2005, 2007–2018
<a href='../mail-eggert.html'>Paul Eggert</a>, Steve
VanDeBogart, and Lei Zhang.
See <a href='../copyright.html'>copying rules</a>.<br />
$Id: assign1.html,v 1.45 2018/09/25 18:13:04 eggert Exp $
</address>
</body>
</html>
<!-- end of HTML resource -->