Final Exam - Keith V. Lucas

advertisement
KEITH V. LUCAS
CIS 312 – UNIX OPERATING SYSTEMS I
LUCASK@SMCCD.NET
Final Exam
CIS 312 – Unix Operating Systems I
Name
Section #1 – General Questions
1.
The operating system acts as a bridge between what two things? (6 points)
Hardware & software
2.
What two things do you need to log into a Unix computer (other than the name of the machine)? (6
points)
Username and Password
3.
What is a shell? (6 points)
A shell is a command interpreter and high-level programming language (e.g. scripting laguage). As
a command interpreter, the shell acts as an interface between users and the operating system. As a
high-level scripting language, the shell can read and sequentially execute files of shell commands.
4.
What’s the difference between a remote machine and a local machine? (6 points)
Local machine is the one you’re physically accessing; remote machine is accessed via the network
using the rlogin command (rlogin is optional for credit).
5.
What is a hierarchical file system? Is Linux a hierarchical file system? (6 points)
A hierarchical file system provides a structure where files are arranged under directories, which are
like folders or boxes. Each directory has a name and can hold files and other directories.
Directories in turn are arranged in a treelike organization. Yes, Linux is a hierarchical file system.
6.
1 OF 6
Define the following commands. (15 points)
Command
Definition
cat
Print the entire contents of a file to stdout
more
Print the contents of a file to stdout page-by-page
less
Print the contents of a file to stdout page-by-page, allowing users to go backward
JUNE 12, 2007
KEITH V. LUCAS
7.
8.
9.
LUCASK@SMCCD.NET
CIS 312 – UNIX OPERATING SYSTEMS I
Draw a line from the following commands to the appropriate definition. (21 points)
grep
Arrange the lines of a file in a specified order
cut
Translate (replace) one character for another in stdin
sed
Search for a regular expression pattern in a (set of) files or any stdin input
tr
Remove columns or fields from one or more files
diff
Remove duplicate adjacent lines from a sorted file
sort
Compare two files line-by-line, sending output to stdout
uniq
Batch-edit a file or set of files, finding and replacing text (among other things)
Set the permissions for a file named foo.txt. (15 points)
Desired Permission
Command
Give everyone read permission, whithout changing any other
permission setting
chmod a=r foo.txt
Give the group write permission, whithout changing any other
permission setting
chmod g+w foo.txt
Grant the following, overwriting all previous permissions:
owner – read, write, execute; group – read; others – nothing
chmod 740 foo.txt
Wildcards are for pattern matching of file names; regular expressions are for pattern matching of
text within files or stdin. For each of the following, write the wildcard and regular expression
patterns that will find the desired files. Remember: it is best to enclose regular expressions in
single quotes. (30 points)
Description
ls wildcard
ls | egrep regex
List all files whose 2nd letter is e
ls ?e*
ls | egrep ‘^.e’
List all files whose 2nd letter is e or f
ls ?[ef]*
ls | egrep ‘^.[e,f]’
List all files that end with . followed
by 3 letters
ls *.???
ls | egrep ‘\....$’
List all files whose 2nd letter is
between e and z inclusive
ls ?[e-z]*
ls | egrep ‘^.[e-z]’
List all files that contain the pattern $(
ls *\$\(*
ls | grep ‘$(’
10. Fill in the following Bash shell commands. (30 points)
2 OF 6
Description
Bash Command
Change directory one level higher
cd ..
JUNE 12, 2007
KEITH V. LUCAS
LUCASK@SMCCD.NET
CIS 312 – UNIX OPERATING SYSTEMS I
Description
Bash Command
List the files in the current directory
ls
List the files in the current directory (long view)
ls –l
List the files in the current directory 1 page at a time
ls | more
Create a file
touch or cat or vi
Know what directory you’re in
pwd
Go to your home directory from anywhere
cd or cd ~ or cd $HOME
Count how many lines are in a foo.txt
wc –l foo.txt
See the permissions of foo.txt
ls –l foo.txt
Move foo.txt to the current directory from its parent
mv ../foo.txt .
Rename foo.txt to bar.txt
mv foo.txt bar.txt
Print the contents of $PATH to the screen
echo $PATH
Look at the first 10 lines of foo.txt
head –10 foo.txt
Look at the last 10 lines of foo.txt
tail –10 foo.txt
Remove all files in a directory, confirming each time
rm –i *
11. Describe the following commands. (21 points)
Command
Description
cp ../foo.txt .
Copies foo.txt from parent to current directory
grep ‘A*b’ foo.txt
Find 0 or more A’s followed by b
grep ‘^bag’ foo.txt
‘bag’ at beginning
grep ‘bag$’ foo.txt
‘bag’ at end
grep ‘b[aeiou]g’ foo.txt
b – vowel – g
ls –l > foo.txt
Sends file listing to a new file instead of stdout
ls | grep ‘foo’
Sends file listing to stdin of grep instead of stdout
12. Is grep case sensitive? Is Unix case sensitive? (6 points)
Yes. Yes.
13. For the following, state whether the path is relative or absolute. (12 points)
3 OF 6
JUNE 12, 2007
KEITH V. LUCAS
CIS 312 – UNIX OPERATING SYSTEMS I
Path
Description
/home/keith
Absolute
../../foo.txt
Relative
home/cis312.spring.2003/j1
Relative (no leading /)
/bin
Absolute
LUCASK@SMCCD.NET
14. Unix has protected memory. What does this mean? Why is this a good thing? (6 points)
Protected memory means that one process cannot accidentally change the memory content of
another. This is good because it prevents programs and the operating system from crashing.
15. When you type the name of a command, how does the shell know where to find it? What happens
if there are two commands with the same name in different directories? (6 points)
$PATH is the search path that the shell uses to find commands. Directories are listed in a desired
order; the first command found is used.
16. What command can be used to get help with other commands? (6 points)
man. Example – “man cd”
17. The /etc/passwd file lists all of the accounts enabled on the machine. The last field contains the
prefered shell (e.g. /bin/bash). What command would you type to count the number of bash shell
users? (6 points)
grep ‘/bin/bash’ /etc/passwd | wc –l or grep -c ‘/bin/bash’ /etc/passwd
18. Which of the following is used to change your password? (6 points)
A. set pass
C. passwd
B. pwd
D. login –passwd
19. Which of the following are handled by the Unix (and Linux) shells? (6 points)
A. wildcards
C. redirection
E. all of the above (A through D)
B. pipes
D. command execution
20. What command will provide you with the number of files in the current directory? (6 points)
A. ls -c
C. ls –n | count
B. ls | wc -w
D. ls -wc
4 OF 6
JUNE 12, 2007
KEITH V. LUCAS
CIS 312 – UNIX OPERATING SYSTEMS I
LUCASK@SMCCD.NET
21. What is the definition of the home directory? (6 points)
Where the users are when they login
22. What does “redirection” do? Give 1 example. (6 points)
Redirects stdout / stdin of a command to / from a file. Example – “echo whoami > aFile
23. What does “pipe” do? Give 1 example. (6 points)
Redirects stdout of a command to stdin of another command. Example – “ls –l | more”
Section #2 – Wildcards
For the next set of questions, assume the following files are in your current working directory:
.book.tar appendix.b
section.1
section.4a
Contents
notes1
section.2
section.5a
Index
notes1a
section.2.bak
section.5a.bak
appendix.a
notes2
section.3
.profile
State which of these files will be listed by the following commands: you can use “all” or “all except” to describe
which of the files in the first 2 questions; for the rest, please write the names of all the files. Your answers must be
case sensitive.
24. ls (6 points)
All files except .book.tar and .profle
25. ls -a (6 points)
All files
26. ls *.* (6 points)
appendix.a, appendix.b, section.1, section.2, section.2.bak, section.3, section.4a, section.5,
section.5a.bak
27. ls i* (6 points)
5 OF 6
JUNE 12, 2007
KEITH V. LUCAS
LUCASK@SMCCD.NET
CIS 312 – UNIX OPERATING SYSTEMS I
NONE – must start with a lower case i
28. ls *.*a (6 points)
appendix.a, section.4a, section.5a
29. ls *.[ab] (6 points)
appendix.a, appendix.b
30. ls ?o*.* (6 points)
NONE – must have o as the second character and . someplace thereafter
Section #3 – Directories
Use the directory structure immediately below to answer the 3 questions.
SomeDir
N
A
K
B
C
Q
F
E
D
M
X
G
J
H
31. Your current directory is A. How would you copy the file foo.txt from the H directory to your
current directory without changing directories? (6 points)
cp ../../<XH/foo.txt .
32. Your current directory is C. How would you move to the G directory is one command? (6 points)
cd ../../../M/X/G
33. Your current directory is Q. How would you delete directories C, E, and F without changing
directories? Assume they are already empty. (6 points)
rmdir C ../E ../../F
6 OF 6
JUNE 12, 2007
Download