COMP2718 Assignment 3

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 by 2:15 p.m. on Monday, February 8.

Consider the following commands used to make a backup of a file:

$ # version 1
$ mkdir backup
$ cp foo backup/foo
$ # version 2
$ mkdir backup
$ ln foo backup/foo

Which version is more efficient, justify your answer. Are there any disadvantages?

*Change this with your answer

Operations on Directories

Assume x is a file, and d is a directory, both in the current directory, describe what happens to the directories . (i.e., the current directory) and d when each of the following commands are executed (the commands are independent). You should state what entries are deleted, changed, or added to each directory.

  1. $ mv x y

    *Change this with your answer

  2. $ mv x d

    *Change this with your answer

  3. $ mv x d/y

    *Change this with your answer

Echo and Globbing

In a terminal window, enter the following:

$ mkdir foo; cd foo
$ touch ab abc de.txt h1.class h3.class

What is output by the following commands:

  1. $ echo h*

    *Change this with your answer

  2. $ echo *[bs]

    *Change this with your answer

  3. $ echo *cl*

    *Change this with your answer

  4. $ echo [ad]*

    *Change this with your answer

Types of Commands

Determine the type (using type) of the following commands. If the command is built in, can you suggest a possible reason why? Usually this relates to information contained within the shell itself.

  1. cd

    *Change this with your answer

  2. type

    *Change this with your answer

  3. history

    *Change this with your answer

  4. ls

    *Change this with your answer

  5. man

    *Change this with your answer

Redirection

Using redirection give the command line that changes echo hi there to:

  1. save the standard output to the file fred.

    *Change this with your answer

  2. append the standard output to fred.

    *Change this with your answer

  3. write both standard output and error to sue

    *Change this with your answer

  4. The same as the previous question using the alternate syntax

    *Change this with your answer

  5. write standard error to err and discard the standard output to /dev/null.

    *Change this with your answer

Shell Expansion

Using the shell expansion ability:

  1. write one command that creates the directories: cs2718/assign1, cs2718/assign2, and cs2718/assignX. Do not assume cs2718 exists.

    *Change this with your answer

  2. write one command that creates the directories: cs2718/assign1/data, cs2718/assign2/data, cs2718/assignX/data. Do not assume any of the directories exist.

    *Change this with your answer

  3. write one command that creates the empty files: a0, a1, a2, a3, a4, a5, a6, a7, and a8. You must use brace expansion.

    *Change this with your answer

More Shell Expansion

How does bash expand the following command line arguments (assume you are using Ubuntu 14.04 in the lab):

  1. $HOME

    *Change this with your answer

  2. "$HOME/afile"

    *Change this with your answer

  3. "$USER"

    *Change this with your answer

  4. $PATH

    *Change this with your answer

Command Substitution

A file called checkthis is created with:

$ echo -e "ls\ncd\ndf\nhistory" > checkthis
  1. Write one command line that uses command substitution to determine the command type, with type, for each command on a separate line from the file checkthis. Show the command line's output.

    *Change this with your answer

  2. Write one command line that uses command substitution to determine the location of the commands listed in checkthis. Show the command line's output. Explain the output.

    *Change this with your answer