<<

Systems Practical 2 Files, Editing, & Submitting∗

Roger Burroughes

This practical consists of three sections:

• how to edit text files with

• how to submit assignments electronically

• how to use file permissions and related utilities

Note, however, that it is important that you should complete the “submit” section of this practical. Leave yourself to do this — even if it means not completing the other sections (although it is in your interest to try anything later, in your own time, that you do not finish in the lab session).

∗Version for 2006/2007

1 Editing Text With Emacs

This section will give you some practice in using Emacs. It is divided into two parts:

• The first section allows you to try out some of the Emacs commands described in the systems lecture.

• In the second section, you will put these commands into practice by editing some text. Either by using some supplied text (a poem by Robert Burns), or by creating your own text (for example, by making notes on some aspect of the course, or on the emacs tutorial itself).

Emacs Tutorial Choose one of the following methods to run the Emacs tutorial:

Method 1: 1. sure you are in your home (” to return to your home directory if you’re not sure — and then “” to check), then make a of the Emacs Tutorial, rename it and put it in your home directory as follows:

˜infteach/system/emacs-tutorial my-tutorial

This takes a copy of the file emacs-tutorial, renames it my-tutorial, and places it in your home directory (assuming you are in your home directory, or have used “cd”).

2. Open the tutorial in Emacs by typing:

emacs my-tutorial

and work through the tutorial to the end. If there are any problems with, or comments on, or questions about the tutorial, make a note of them.

Method 2: 1. Start emacs from the command line (just type “emacs” the prompt and hit “Return”) or Select “Emacs Text Editor” from the “Applications ⇒ Programming” menu.

2. Select “Emacs Tutorial” from the “” menu at the of the Emacs window.

To Quit: 1. When you’ve finished, type “Ctrl-x, Ctrl-s” to save it1, then “Ctrl-x, Ctrl-” to quit.

Practice In Using Emacs Make a copy of ˜infteach/system/poem in your home directory (use “cp ˜infteach/system/poem poem” from the command line — this will make a copy in your current working directory). Once you have done this, open the file with Emacs:

% emacs poem

1If you selected the “Emacs Tutorial” from the “Help” menu, the file will be saved as “TUTORIAL” in your home directory.

2 (note that you get a new Emacs window, and no return of the Unix prompt in the invoking terminal window - you won’t get the prompt back until you quit Emacs).

1. You will see that the underlining of the title is mis-aligned. Move the cursor (using the mouse or emacs command keys) to the second line and insert the appropriate number of spaces in front of the underlining. If you put in spaces than you meant to, you can remove the surplus with the “←−” (Backspace) key. 2. The first line of the seventh stanza (line 34 of the file) is incomplete. At the moment it reads:

They’ve ta’en a weapon, and ,

It should read:

They’ve ta’en a weapon, long and sharp,

Insert the necessary words (use “Ctrl-U 3 4 Ctrl-N”2 to go to the correct line — assuming the cursor is at the top of the file, or use the mouse and cursor keys). 3. The eighth stanza is full of spelling mistakes — go through and correct them all (use -checking for this — see under “Other Useful Commands” in the reference section of the lecture notes). 4. The second last stanza has some (obvious!) rubbish at the end of it, so remove everything from “All of the next...” to “end of the junk”3. 5. The second and third stanzas are in the wrong order. Select the text to be moved (the second stanza and the blank line below it) by moving the cursor to the start of the second stanza, click and hold down the left mouse button, and drag the cursor down to the end of the stanza and release the button — you should see the text highlighted as you move, and it should stay highlighted when you release the mouse button. The highlighted lines are a “region”, and can be out of the file with “Ctrl-”. You can then move the cursor to the first line of the fourth stanza and the text back in with “Ctrl-Y”. If you move the cursor after cutting, and before pasting, you can move regions of text around the file

Take a look at the “Edit” menu. The “Cut” and “Paste” commands just used are duplicated here, as well as two related commands:

• Copy lets you duplicate the selected region by making it available for pasting without having to cut it first. • lets you remove the selected region by cutting it without making it available for pasting.

Notice how the menu items are greyed out: they are not available for you to use when there is no region highlighted. There’s also the very useful “Undo” command in the “Edit” menu that will undo your last editing command.

• Make some comments on your experiences with the Emacs tutorial, using any notes you took during the work-through above (or make some up — we only need text to type here!)

Once you’ve finished, save your file and Emacs (see the “To Quit” section of the “Emacs Tutorial” section above).

2This is how you give a numeric argument, in this case “3 4” (for 34). The next command or keystroke is executed this number of times, in this case “Ctrl-N” (next line) so the cursor moves down 34 lines. 3Note that entire lines can be deleted with “Ctrl-K” (assuming you’re at the start of the line — otherwise “Ctrl-K” just deletes from the current cursor position to the end of the line).

3 Electronic Submission of Work

This section demonstrates the “submit” command, used to submit coursework electronically. The requirement here is simple — to successfully use the submit command to submit the results of the Emacs4 practical. Once you have completed your work, and created a file containing your submission (let’s — for the sake of this example — call the file “submission”), you need to submit it with the submit command, and you will require the exercise (or practical) name (or code). For this exercise, the code is “se1” — the command should therefore be5:

% submit inf1 inf1a se1 submission

If you just type the command “submit” you will be given a list of the valid options (in the output below, long lines are truncated):

% submit

submit 2.63.1-1.dice.0 usage: to submit an exercise: submit ... where the is some integer and can be a regular or a directory.

You need to specify year you are in. Valid ’Year’ choices are: msc (courses: vis-5 tts-5 tm-5 tdd spnlp-5 rl propm ppls-5 ... inf2 (courses: inf2d inf2c inf2b inf2a) inf1 (courses: inf1b inf1a) cs4 (courses: vis-4 tpl slip qsx ppls-4 pa-4 ms-4 hci-4 fpl... cs3 (courses: st seoc sdp pi os lsi ip fps ec dbs ct cs com... cs1 (courses: cpmt cp1 cl1) cg1 (courses: hc1 fmcs1) ai4 (courses: tts-4 tm-4 spnlp-4 masws-4 lfd-4 kmm-4 iar-4 ... ai3 (courses: pi lp kre ivr ics icl gagp ailp abs) (courses: test5 test4 test3 test2 test1)

SUBMISSION DID NOT HAPPEN! %

If you get the exercise name (practical code) wrong (and can you see what’s wrong with the incorrect example command below?), you will see the following:

% submit inf1 inf1a se2 submission

submit 2.63.1-1.dice.0 usage: to submit an exercise: submit ... where the is some integer and can be a regular file or a directory.

The exercise name should be one of: se1 fp4 fp3 fp2 fp1 cl4 cl3 cl2 cl1 for course inf1a of year inf1.

4If you do not complete the Emacs part of this practical, submitting any text file will do – the important thing is to successfully use the submit command, not what you actually submit! 5In these examples, the Unix prompt is represented by the % symbol.

4 SUBMISSION DID NOT HAPPEN! %

Note that submit will always tell you if the submission completes or fails — you will see either “SUBMISSION DID NOT HAPPEN!” or “Submission... succeeded”. Using the earlier example (a file called ’submission’ from the home directory ’/home/infteach’, for the module ’inf1a’ and year ’inf1’, with exercise number ’se1’) we should see:

% submit inf1 inf1a se1 submission

Submit the following for exercise se1, module inf1a of the inf1 course. /amd/nfs/pegasus/disk/ptn041/infteach/submission Is this correct (y/n: n aborts)? y

Submission of the following for exercise se1, module inf1a of the inf1 course succeeded: /amd/nfs/pegasus/disk/ptn041/infteach/submission %

Note that you may see either the long or the short version of the pathname for your file echoed back in the response (in this example, either /amd/nfs/pegasus/disk/ptn041/infteach/submission or /home/infteach/submission). Either is OK — they both refer to the same file. So, try submitting your version of ’poem’ (whether fully corrected or not):

• Make sure you have a single file that contains the work you want to submit.

• Identify the arguments you will use with the submit command (that’s the codes for year, course, and exercise/practical, plus the name of your file).

• Use the submit command with the appropriate arguments to submit your work.

When you think you have successfully submitted the file, you can check with the show submissions command:

% show_submissions inf1 EXERCISE LAST YEAR MODULE NAME MODIFIED SIZE(bytes) NAME ======inf1 inf1a se1 Thu, 23, Sep 8:15 3589 submission %

Note that show submissions displays every file that you have submitted for every exercise, it does not show files submitted by other users.

5 Unix Files

This section will give you some practice in finding out information about files.

Unix Commands & Utilities 1. Look at the manual page for , or “ls --help”, and acquaint yourself with all the various options and flags. Work out how to do listings in colour, and without colour.

NOTE: If not already configured, “ls --color” or “ls --color=” should work, and “ls --color=no” should disable it (on a per-command basis). By default, colour is not used to distinguish types of files. That is equivalent to using “--color=none”. Using the “--color” option without the optional “WHEN” argument is equivalent to using “--color=always”. With “--color=auto”, colour codes are output only if standard output is connected to a terminal ().

2. This next one may take a bit of working through — feel free to skip it if you’re short of time! The for ls refers to the command. Using “info ls” (“q” to quit), see if you can identify all the parts of the output of “ls -o .bash ” (assuming you are in your home directory). You’ll need to work out how to drive “info” first! For more info on info, see the “info” man page — note that there’s more than one “info”, so you’ll need to specify which section of the manual you want to look in (use “man 1 info”).

NOTE: Invoke “info ls”; move cursor to start of “* What information is listed::” line and hit “Return”. Scrolling down should reveal: “In addition to the name of each file, print the file type, permissions, number of hard links, owner name, group name, size, and timestamp ...”

3. Identify which group you are in. There are (at least) two ways to do this — what are they?

NOTE: Running the “groups” command, or using “ls -g”.

4. Identify the recently modified file in your home directory (Hint — check flags for “ls”).

NOTE: Use “ls -ot” — most recently modified file should be first in list.

5. Using the spell command, examine the file poem in ˜infteach/system. Why is “plough” one of the words listed?

NOTE: “spell” uses an American word list — in which “plough” is an error.

6. How many characters does the poem file have?

NOTE: Use “ -c /home/infteach/system/poem”, or “wc /home/infteach/system/poem” and take the third number (it should be 3589).

7. Using the file command, examine the files in the ˜infteach/Files directory. Do you agree with what file says? (There is at least one file that it gets wrong — albeit understandably.)

NOTE: “Comments.html” is HTML, not “ASCII English text”, and “map2.pl” is Prolog data, not “ASCII C program text”.

6 File permissions 1. Identify the file-permissions field in the output of “ls -o /home/infteach/system/poem”. Which characters of this field represent “user” permissions? can read this file, and who can modify ( to) it?

NOTE: “user” permissions are shown in character positions 2-4 of the first field on the line, and should be “rwx”. Everyone should be able to read it, but only the owner should be able to write it.

2. If you don’t already have a copy of /home/infteach/system/poem, take one (using “cp”). Using the command, remove read permission for everyone but yourself. If someone else is willing to test this, check to see if they can read the file (with “”, for example).

NOTE: “chmod go-r poem” (assuming the user is in the same directory as the poem file).

Special characters 1. The “*” character matches everything. How would you specify all filenames (and directories) in the current directory which contain the string “some”? (There are two instances of this filename in the “˜infteach” directory — test your answer using “ls ˜infteach/”).

NOTE: Use “ls ˜infteach/*some*”.

2. The “?” character matches one character only. How would you use it to match all files of eight characters?

NOTE: Use “ls ????????”.

3. How would you use “*” and “?” to list filenames of at least four characters?

NOTE: Use “ls ????*”

Chaining commands together 1. Roughly how many files do you have in your home directory?

NOTE: Use “ls ˜ | wc -l”

2. How many files are in the “˜infteach” directory6?

NOTE: Use “ls ˜infteach | wc -l”. Note that you can also use “ls -1 ˜infteach | wc -l”, but that “ls” should default to use “-1” when output through a pipe.

3. There may be more files in “˜infteach” than will fit on one screen. How would you use a pager (for example, “less”) to display only a screenful at a time?

NOTE: Use “ls ˜infteach | less”

6If you use “ls -o” you may need to use the “-L” flag too, as “ls -o” may show you that “infteach” is just a (shortcut) to another location. The “-L” flag hides this confusing fact.

7