COMP 3000 Lab 1 2012

From Soma-notes
Revision as of 13:13, 20 September 2012 by Soma (talk | contribs)
Jump to navigation Jump to search

In this lab you will be learning about the standard command shell on Linux, bash.

For reference material, we suggest you look at this tutorial on the shell and the associated book The Linux Command Line (available as a PDF for free and in print). You may also use other Internet resources or other people. Please cite all sources that you use to answer the questions in this assignment.

You should turn in Lab 1 by 8 PM on Monday, September 24 via cuLearn. (Normally the due date is Friday, but mistakes were made and there was a power outage.) Your answers should be in plain text (the true UNIX file format) or PDF. No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format). Note the lab has 50 points in total.

You should expect to complete Part A in tutorial. You should submit the answers to both Part A and Part B, however, on Friday.

You should use this as an opportunity to become familiar with the UNIX command line. After this lab it will be assumed that you are reasonably fluent in basic shell usage. If you do not feel so comfortable, you should study the above mentioned references.

Part A

  1. [8] What is your username on this wiki? Have a TA help you create an account.
  2. [1] What Linux distribution are you using? What version? You should look at the file /etc/issue generally to find out.
  3. [1] What shell do you get by default when you log in? Check by running echo $SHELL. If it is not bash, then type exec bash to switch to it.
  4. [1] Is your Linux environment running virtualized or on bare metal? How do you know? (If you aren't sure, say so, but explain why.)
  5. [1] Who installed and configured your Linux environment? What level of access do you have to it?
  6. [2] A shell command can be one of four things. What are those four things? Explain very briefly.
  7. [2] On the machine you are on, in what directories are commands external to the shell stored? How can you get this information on the command line?
  8. [2] Compare the commands ls /usr/bin | more and ls /usr/bin | less. How is the output similar? How are they different?
  9. [1] How would you create an empty file with the filename empty file.txt? (Yes, that is a space in the filename.)
  10. [1] How would you output the contents of this file?

Part B

  1. [4] Some shell commands, such as pwd, are both built-in and are external. What is one reason why both versions might be present?
  2. [4] What are the permissions on your Linux home directory? With those permissions and your knowledge of the other accounts on the system, who has access to your home directory, and what sort of access do they have?
  3. [10] Give one or more command line strings that use the following operators: >, <, >>, <<, |. Explain briefly what each operator is doing in your examples, both concretely and in terms of STDIN and STDOUT.
  4. [2] Are there operators that work specifically with STDERR? Explain briefly.
  5. [2] How do you use these operators with other file descriptors? Explain briefly.
  6. [2] Give an example of a bash for loop and explain what it does.
  7. [2] Give an example of a bash if statement and explain what it does.
  8. [2] With the & you can put processes in the "background". Given that external commands are always run as separate processes from the command shell, what is the key difference between foreground and background processes?
  9. [2] What are the differences between shell and environment variables? Specifically, what processes have each of them, and to what extent are they shared? HINT: look at the execve system call.