COMP2718 Lab 4

Your Name -- Your Student Number

Complete this assignment by downloading this HTML file and editing it (using a text editor---not a special HTML editor). Wherever you see emphasized text (e.g. "Your name" and "Your Student Number" above) you should insert your own text, as appropriate. Submit via D2L at the end of the lab period.

The vi Editor

  1. Complete the tutorial at openvim.com. (There appear to be some minor bugs in this tutorial. Also some bad jokes.)

  2. For all subsequent questions, you should have a running instance of vi (actually vim) and be making changes to the file Img.h available within the following git repository: https://gitlab.com/COMP2718/lab4_init.git.

Note that your answers to the following questions should all be executed in command mode (a.k.a. normal mode). When questions ask for a specific number of keys (e.g. a 2-key command) hitting the Escape key to return to command mode does not count.

  1. There is a misspelled word on line 25. What keys can you enter to reach line 25 from any other line in the file.

    Change this with your answer

  2. Go to the beginning of this line by typing 0. What 3-key command can you use to get to the second 't' in "Construt". (One could also just move the cursor with 'l' but we are looking for a more efficient way here.)

    Change this with your answer

  3. What 2-key command fixes the typo.

    Change this with your answer

  4. Search for the term "inWidth" using "/". What sequence of keys replaces the "inW" with "w". There are multiple possible answers.

    Change this with your answer

  5. Give the ex-command that will substitute all instances of "inWidth" with "width".

    Change this with your answer

  6. Execute ":help <". Now give the keys to unindent all lines in the file, starting at the first line of the file..

    Change this with your answer

Processes

In this exercise, you should start the firefox browser (from the window manager) as well as two terminal windows.

  1. The ps command with no arguments will list only the processes attached to the same terminal as the ps command. In one of the terminals, execute ps and show the output below.

    Change this with your answer

    What is the TTY?

    Change this with your answer

  2. Record the output of ps for the other terminal.

    Change this with your answer

    What is the TTY? Change this with your answer

  3. Using the PID of bash from the first terminal, enter this command in the second terminal:

    % kill -9 PID_OF_BASH
    

    Describe what happened?

    Change this with your answer

  4. Consult the course notes or use man ps to discover how to list all the processes. Use a pipeline command to show only the lines containing firefox. Command

    Change this with your answer

    Look at the output and identify the PID of the firefox process. What command could you use to kill the firefox process?

    Change this with your answer

    Attempt to kill firefox. Record what happened?

    Change this with your answer

  5. Relaunch firefox, and goto cbcnews.ca and play any video. In a terminal window, type the command top. After 10 seconds stop the video from playing. Observe the terminal containing top, how has the information about firefox changed?

    Change this with your answer

Bash Environment

  1. Using the printenv command, determine the value of the following environment variables. HOME

    Change this with your answer

    USER

    Change this with your answer

    TERM

    Change this with your answer

    PATH

    Change this with your answer

    PS1

    Change this with your answer

    SHELL

    Change this with your answer

  2. The PS1 variable controls the prompt used by BASH. Using man bash and search for the PROMPTING section to see how to configure the prompt. User PS1=STRING to change the prompt by customizing STRING. First set the prompt to display the current time in 12 hour format followed by the current directory.

    Change this with your answer

    Change the prompt to display the host name followed by the current user's name.

    Change this with your answer

    Change the prompt to display the base name of the current directory and the history number of the this command line. Change this with your answer

  3. Change the PATH with the following command:

    $ PATH=/bin
    

    Determine which of the following standard commands are still available: mv, grep, less, cp, cd, which, and firefox. Available

    Change this with your answer

    If the PATH is changed to:

    $ PATH=/bin:/usr/bin
    

    Which of the missing commands are now available:

    Change this with your answer

  4. Change the HOME variable to /tmp. Now type cd. What is the current directory.

    Change this with your answer

  5. In a new terminal window, use an editor to edit the ~/.bashrc file. At the end of the file add the following line:

    alias d="date +'%D %T'"
    

    Save the file and quit from the editor. Open another terminal window. In the new terminal, type the command d. What happened?

    Change this with your answer

    In the original terminal, type d and explain the result.

    Change this with your answer