BCS 215 (Unix Operating Systems)
Exam #1: 2018 March 6th
In your home directory /home/students/yourid/
(where "yourid" is
YOUR login name)
create a subdirectory named
"exam1"
and do all work in
~yourid/exam1/.
To allow this exam to be graded,
make sure that permission modes for these directories
(750 or 755)
allow members of the
"students" group
to read or search for file names.
|
-
The following text files are in my sub directory which is also named "exam1/", i.e. ~martinb/exam1/:
- signers
- amendments
- presidents
- capitals
In your own ~/exam1/ directory,
create a hard link to each of these four text files.
-
Do the following in your exam1/ directory:
- Create a file named "heads", containing the first FIVE lines of each of the 4 files.
- Use the "wc" command to determine how many lines are in each of these five files
and redirect the output to a file named "lines".
- Copy "signers" onto a new file named "s".
- Append the contents of "lines" to the "s" file.
Make sure you append to "s" rather than overwrting it! (Size should be about 1000)
If "s" was destroyed by mistake, repeat the previous two commands.
- Sort your "s" file onto a file named "ss".
- Copy "ss" to a new file named "tt".
-
The home directories for everyone in our group are contained in "/home/students/"
(which is also "../../"
when "exam1/" is your working directory).
Create and enter one-line commands to do the following:
- Count the total number of students; save the answer on a file named "many".
- Count how many students have names beginning with the letter "q",
and save the answer on a file named "q".
-
Count how many students have names beginning with
either 'x' or 'y' or 'z',
and save the answer on a file named "xyz".
- Count the total number of words in all of the files in your "exam1/" directory, and save that total on a file named "toomany".
NOTE: You may use the "cat command to concatenate the lines in several files,
but your one-line command must NOT create any new files.
-
In "exam1/",
create five subdirectories named d0, d1, d2, and d3;
set permissions on these subdirectories as follows:
- Anybody may add or remove known files in d0/ but only members of the "students" group may search the d0/ directory.
This means that anybody may access a file -- if they know its name -- but only members of the
group may search for unknown file names.
- Nobody else but you may add or delete files in d1/
but group members may access files or search for unknown file names; others may not access a file n d1/ -- even if they know the name.
- Everybody has permission to access files in d2/ and everybody can search it; only you can add or delete files in d2/.
- Only you can access files in d3/ (and nobody else can).
-
In "exam1/",
create three empty files named a, b, and c,
and set file permissions on these files as follows:
- Anybody may read or write file "a" but nobody can execute it.
- Only members of "students" may read "b"; only you may write or execute it.
- File "c" is read only for all.
Only you may execute it; nobody can change it.
-
More links:
- In each subdirectory
d0/, d1/, d2/, and d3/,
create hard links to the file called "a"
with names
"a0", "a1", "a2", and "a3"
respectively
- In d0/, create a link to the file "b" and call this link "b0"
- In d1/, make a new empty file named "e"
- In d2, three hidden files:
-
Use the cmd "ls -l d2" to view the names of all visible files in d2/ and display the results.
Then, repeat the command and redirect its output to a file named "d2names".
Enter a command line to remove the d2/ directory, then
create a file named "d2error" containing a sentence that says what happened and why.
- The grep command extracts all lines of a file that match a pattern.
Create and enter one-line commands to do the fillowing:
- Count the number of lines in "signers" containing "George" and write the result in a new file named "g".
- Count lines in "presidents" that contain "George" and append the result to the "g" file.
- Count lines in "capitals" containing "City" and append the result to the "g" file.
- Edit your sorted copy ("tt")
to make the following changes to the text:
- Change every instance of the name "John" to "Johnny"
- Change every instance of the name "Lewis" to "Lou"
- Change every instance of the name "Thomas" to "Tom"
- Change every instance of the name "William" to "Bill"
-
Use the "diff" and "comm -12" commands to compare the two files "ss" and "tt":
- Write the diff results on a file named tt.diff
- Send the comm results on a file named tt.comm
(Don't be surprised if comm complains that file2 is sorted.)
The command "cut -f1" extracts only the first column of a file.
-
Use this "cut -f1" command to create two files, ss1 and tt1, that contain only the first column of files ss and tt.
- Using the "comm -12" command, count the number of lines that are common to both ss1 and tt1, and write the answer to a new file named "common".
When you are all done, save the command-line history onto a file named "h".
(Hint: Use the history command and redirect stdout.)
Make a copy of h in d1.
Create a hard link in d2 to the copy of h in d1.
BCS 215 (Unix Operating Systems)
Exam #2: Due 2018 March 9th (by 10pm Friday)
In your home directory /home/students/yourid/
(where "yourid" is YOUR login name)
create a subdirectory named
"redo2"
and re-do all of the above in
~yourid/redo2/.
You may use anything in
~yourid/exam1/,
but DO NOT MODIFY anything in
exam1/
after 3pm Tuesday 3/6.