[Solved] . Assignment 1. Linux and Emacs scavenger hunt

$25

File Name: ._Assignment_1._Linux_and_Emacs_scavenger_hunt.zip
File Size: 433.32 KB

SKU: 345363 Category: Tag:
5/5 - (1 vote)

Instructions: Use the commands that you learned in class to find answers to these questions. Dont use a search engine like Google, and dont ask your neighbor. If you need a hint, ask the TA. 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. As you do actions, use a Linux-based editor to record your keystrokes and each answer in files key1.txt and ans1.txt that you will submit as part of the assignment.

  1. How can you get man 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: man man)
  2. Where are the cp and wc programs located in the file system?
  3. What executable programs have names that are just one character long, and what do they do?
  4. When you execute the command named by the symbolic link /usr/bin/cc, which file actually is executed?
  5. The chmod program changes permissions on a file. What does the symbolic mode g-s mean, in terms of permissions?
  6. What option to find lets you search for files that have been modified in the last 3 days?
  7. Use the previous answer to find all directories modified in the last 3 days.
  8. Of the files in the same directory as find, how many of them are symbolic links?
  9. What is the oldest regular file in the /usr/lib directory?
  10. Where does the locale command get its data from?
  11. In Emacs, what commands have sort in their name?
  12. Briefly, what do the Emacs keystrokes C-a through C-z do? Can you list their actions concisely?
  13. In more detail, what does the Emacs keystroke C-g do?
  14. What does the Emacs yank function do?
  15. When looking at the directory /usr/bin, whats the difference between the output of the ls -l command, and the directory listing of the Emacs dired command?

Homework: Learning to use Emacs

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.

To start, download a copy of the web page youre looking at into a file named assign1.html. You can do this with Wget or cURL. Use cp to make three copies of this file. Call the copies exer1.html, exer2.html, and exer3.html.

Exercise 1.1: Moving around in Emacs

  1. Use Emacs to edit the file exer1.html.
  2. Move the cursor to somewhere in the first line that contains the text ASCII.
  3. Move the cursor to somewhere in the first line that contains the text Instructions.
  4. Move the cursor to the first letter of first occurrence of the word HTML.
  5. Move the cursor to the first letter of first occurrence of the word hunt.
  6. Move the cursor to the end of the current line.
  7. Move the cursor to the beginning of the current line.
  8. Move the cursor back to somewhere in the first line of the file.
  9. Have you been moving the cursor using the arrow keys? If so, repeat the above, without using the arrow keys.
  10. 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?
  11. When you are done, exit Emacs.

Exercise 1.2: Deleting text in Emacs

  1. Use Emacs to edit the file exer2.html. The idea is to delete its HTML comments; the resulting page should display the same text as the original.
  2. Delete the 18th line, which is an HTML comment. <! HTML comments look like this. >
  3. Delete the HTML comment containing the text DELETEME DELETEME DELETEME.
  4. Delete the HTML comment containing the text http://en.wikipedia.org/wiki/HTML_comment#Comments.
  5. Theres one more HTML comment; delete that one too.

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 exer2.html. Also, check that you havent deleted something that you want to keep, by using the following command:

diff -u exer1.html exer2.html >exer2.diff

The output file exer2.diff should describe only text that you wanted to remove. Dont remove exer2.diff; youll need it later.

Exercise 1.3: Inserting text in Emacs

  1. Use Emacs to edit the file exer3.html.
  2. Change the first two instances of Assignment 1 to Assignment 37.
  3. Change the first instance of UTF-8 to US-ASCII.
  4. Insert a blank line after the first line containing <ol>.
  5. When you finish, save the text file and exit Emacs. As before, use the diff command to check your work.

Exercise 1.4: Other editing tasks in Emacs

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.

  1. Execute the command cat exer2.html exer2.diff >exer4.html to create a file exer4.html that contains a copy of exer2.html followed by a copy of exer2.diff.
  2. Use Emacs to edit the file exer4.html. The idea is to edit the file so that it looks identical to exer1.html on a browser, but the file itself is a little bit different internally.
  3. 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.
  4. Repeat the process, until the earlier part of the file is identical to what was in the original.
  5. Delete the last part of the file, which contains the diff output.
  6. except we didnt really want to do that, so undo the deletion.
  7. Turn the diff output into a comment, by surrounding it with <! and >.
  8. Now lets try some search and replaces. Search the text document for the pattern <ol>. How many instances did you find? Use the search and replace function to replace them all with the initial-caps equivalent <Ol>.
  9. Check your work with viewing exer4.html with an HTML browser, and by running the shell command diff -u exer1.html exer4.html >exer4.diff. The only differences should be changes from <ol> to <Ol>, and a long HTML comment at the end.

Exercise 1.5: Doing commands in Emacs

Do these tasks all within Emacs. Dont use a shell subcommand if you can avoid it.

  1. Create a new directory junk thats right under your home directory.
  2. In that directory, create a C source file hello.c that contains the following text. Take care to get the text exactly right, with no trailing spaces or empty lines, with the initial # in the leftmost column of the first line, and with all other lines indented to match exactly as shown:
    #include <stdio.h>intmain (void){  char n = '
    ';  char b = '\';  char q = '"';  char const *p = "#include <stdio.h>%cint%cmain (void)%c{%c  char n = '%cn';%c  char b = '%c%c';%c  char q = '%c';%c  char const *p = %c%s%c;%c  printf (p, n, n, n, n, b, n, b, b, n, q, n, q, p, q, n, n, n, n);%c  return 0;%c}%c";  printf (p, n, n, n, n, b, n, b, b, n, q, n, q, p, q, n, n, n, n);  return 0;}
  3. Compile this file, using the Emacs compile command.
  4. Run the compiled program, and put its output into a new Emacs buffer named hello-out.
  5. Copy this buffers contents directly into the log that youre maintaining for this exercise. (You are using Emacs to maintain the log, arent you?)

Exercise 1.6: Running Elisp code

  1. Visit Emacss *scratch* buffer.
  2. In the buffer, compute a random integer by invoking the random function. Use C-j (eval-print-last-sexp) to invoke the random function.
  3. In the buffer, assign three random integers to the global variables x, y and z. You can start by executing (setq x (random)). Again, use C-j.
  4. What is the product of the three variables? You can find this out by executing (* x y z). What do you observe about the result? If the answer seems to be the correct mathematical answer, try again with a different set of random integers.
  5. Try evaluating (* x y z) again, but this time with M-: (eval-expression). What difference do you observe in the output?
  6. Are the random integers truly random in the mathematical sense? If not, whats not random about them?

Submit

Submit the following files.

key1.txt

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., e m a c s SP e x e r 1 . h t m l Enter) or to type in the complicated C program of Exercise 1.5. Write down the label of the key for each keystroke, e.g., a, A (if you type a while holding down the shift key), Tab, Enter, Esc. Use SP for space. Use prefix C- and M- for control and meta characters: e.g., C-f represents Control-F, and M-f represents Meta-F. Put a space between each pair of keystroke representations. For example: e m a c s < v i Backspace Backspace Backspace > v i. If you use some key not described above, invent your own ASCII name for the key and explain what key you mean, but dont put spaces in your key name.

ans1.txt

Answers to each lab question, along with a very brief description of how you can easily find such the answer from a new Ubuntu system, the next time you need the answer.

The .txt files should be ASCII text files, with no carriage returns, and with no more than 80 columns per line except when logging program output longer than that. The shell command:

awk '/r/ || 80 < length' key1.txt ans1.txt

should output only a small number of log lines.


2005, 20072015 Paul Eggert, Steve VanDeBogart, and Lei Zhang. See copying rules.$Id: assign1.html,v 1.36 2015/09/21 19:50:15 eggert Exp $
Shopping Cart
[Solved] . Assignment 1. Linux and Emacs scavenger hunt
$25