Explorer Post 891 Name: Intro to Unix Final Exam February 26th

advertisement
Explorer Post 891
Intro to Unix
Final Exam
February 26th, 2014
Name:____________________
This exam is 5 pages long, excluding this cover sheet. Please ensure you have
all pages before the exam starts.
This test is out of 110 points spread across 13 questions. There are also a total of 6 bonus
points available.
During the exam, no devices are permitted that facilitate communication with another party
(e.g. cell phones, and other wireless electronic communication devices including laptop computers). Students may not leave the examination room without permission of the instructor
(who will be sitting in the room) and while out of the examination room, no student may
discuss any part of the examination with anyone who has not taken the exam, either in
person or through an electronic communications means.
Question Points Score
1
10
2
10
3
5
4
5
5
10
6
10
7
10
8
10
9
10
10
5
11
5
12
5
13
15
Total:
110
Explorer Post 891: Introduction to Unix Exam
1
1. Unix-like operating systems utilize directories, sometimes called folders, to group files
and other directories. For each of the following statements, give the command that
would be used to accomplish that task.
(a) (2 pts) List the contents of the current directory
(b) (2 pts) List everything (including hidden files) in a directory
(c) (2 pts) Create (or make) a new directory
(d) (2 pts) Remove an empty directory
(e) (2 pts) Change the current working directory
(f) (2 points (bonus)) Print the current working directory
2. In addition to directories, Unix-like operating systems also have files, which can perform
many different roles. For each of the following statements, give the full command that
would be entered at a command prompt.
(a) (4 pts) Copy a file named beep into a file named boop
(b) (4 pts) Remove a file named boop
(c) (2 pts) Put the contents of the file beep to the screen
3. (5 pts) When we discussed the command mv, we explained that it performed two common system tasks that deal with files. What were these two tasks?
4. (5 pts) In class, we discussed two commands that would print the last few lines or first
few lines of a file or a pipe. What were these two commands?
Explorer Post 891: Introduction to Unix Exam
2
5. A common tool for dealing with groups of files is grep. Given the following command,
answer the following questions.
grep -i "dave" /etc/passwd
(a) (2 pts) What is the significance of the -i in this command? In other words, what
does it mean or stand for.
(b) (8 pts) Explain, in your own words, what this command is doing and what the
output of this command would be.
(c) (2 points (bonus)) What things are stored in the file /etc/passwd
6. Unix-like operating systems utilize the idea of standard in and standard out. In class, we
gave examples of how output from programs could be sent to files, or to other programs.
(a) (4 pts) Given that the program wc -l will output the number of lines given as
input, how would output the number of lines from the grep command in the previous
question
(b) (4 pts) How would we write the output from the grep command in the previous
question to a file?
(c) (2 pts) What is the difference between > and »
7. Files in Unix have permissions, allowing system administrators power to control access
for different files. Consider the following output from ls -l
-rwxrw-r–- 1 chris staff 2450 Sept29 11:52 test
(a) (4 pts) Who has read access to this file? Write access?
(b) (4 pts) Is this a file or a directory? How can we tell?
(c) (2 pts) What command would we use if we wanted to change the permissions to
this file?
Explorer Post 891: Introduction to Unix Exam
3
8. Directories can be accessed via absolute and relative paths. Consider the following
directory tree:
(a) (5 pts) Starting from the folder ee51vn, what is the relative path to pg1? (Hint:
. is the current folder and .. is the folder one up in the tree)
(b) (5 pts) What is the absolute path to pg1?
Explorer Post 891: Introduction to Unix Exam
9. (10 pts) (1 pt each) Matching
(a) ˜
(b) *
(c) man
(d) 644
(e) 755
(f) ps
(g) expr
(h) .profile
(i) PATH
(j) while
__ Command to do math and print the result
__ File that stores things you would like to run every time you login
__ Command to show how to use commands
__ Wildcard for file/directory listings
__ Command to show processes
__ Read/Write for owner, Read for group/other
__ Your home directory
__ Variable that stores the directories to look for executable commands
__ A type of loop
__ Read/Write/Execute for owner, read/write for group/other
4
Explorer Post 891: Introduction to Unix Exam
5
10. At the beginning of shell programs, we had the following line:
#!/bin/bash
(a) (5 pts) What is the significance of this line? What does it mean?
(b) (2 points (bonus)) What is this line’s affectionate nickname? Why?
11. (5 pts) What character do we place in front of a variable to “access” it’s value?
12. (5 pts) When writing our Rock Paper Scissors game, we used a built-in variable called
RANDOM. Why/when did we use this, and what is it’s significance?
13. Write a shell program that:
(a) (5 pts) Prompts a user to input a number and reads that number to a variable
(b) (10 pts) If the number is greater than 50, print “that is a large number”, otherwise
print “that is a small number”
Download