A 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

CSCI 2132 Software Development

Assignment 2
Due: Thursday, Oct 3, 2013 by 8 AM EST
Price : 45 $
Assignment Instructions:
Each question of this assignment requires that you create one or more files . Use the
exact names (case-sensitive) as specified by each question.
You need to create a directory named a2 that contains the files specified in all questions.
Submit this directory using the command submit.
All the answer files must be textual Unix files, for example created with emacs or vi, or
recordings of the script command.
Q1) (10 marks) Submit answers to this question in a plain text file called a2q1.txt.
(a) Briefly explain how shell interprets the tokens >, <, and >>.
(b) How is the token 2> interpreted, and what is the meaning of the number 2?
Q2)

(10 marks) Submit answers to this question in a plain text file called a2q2.txt.

Let us assume that we have a regular file f1, a file f2 that is a hard link to f1, and a file
f3 that is a soft link to f1.
(a) Let us assume that all three files, f1, f2, and f3 have the same user owner. If we
change the owner of f1, is the owner of f2 going to be changed? How about owner of f3?
Explain your answers.
(b) If we remove f1, will f2 still be a valid file? Will f3 still be a valid file? Valid means
that, for example, we can display the contents of the file. Explain your answers.
Q3)
(10 marks) This question requires that you use wildcards. Use ls command to
perform the tasks below without using any other command, and use script to record
your most successful execution. Your command lines must work no matter what the
current working

directory is. The names of the files to be generated by script for the three questions below,
are a2q3_a.txt, a2q3_b.txt, and a2q3_c.txt.
(a) Print a list of files in the directory /usr/bin whose names contain at least two minus
signs. One such file is /usr/bin/git-ls-tree.
(b) Print a list of files in the directory /usr/bin whose names end with a digit.
(c) Print a list of files in the directory /usr/bin whose names end with a digit, start
with a letter that is not p, and are at least 6 characters long.

Remark :

I would just like to remind you that at the beginning of Question 3 it is


explicitly stated that you must use only "ls" command (e.g., you cannot
use the "grep" command).
Also
Please pay attention to the following sentence in Q3: "Your command lines
must work no matter what the current working directory is."
Since you are looking at the files in the /usr/bin directory, you
obviously need to specify this somehow.
A couple other notes regarding this question:
1. Again, "ls" is mandatory command, and no other command.
2. Wildcards are similar but not the same as regular expressions. In
particular, "*" is used in a different way. You are supposed to use
wildcards in Q3.
You should remember that we had in class examples such as:
ls *.java
ls ../a/*.java
ls /etc/a*
-There were a couple of typos in question 3. They are probably easy to
spot, but it is important to be aware of them. The assignment reads:
The names of the files to be generated by script, for the

four questions below, are a2q2_a.txt, a2q2_b.txt,


and a2q2_c.txt.
but actually, this is Question 3 and there are only three sub-questions,
so it should be:
The names of the files to be generated by script, for the
three questions below, are a2q3_a.txt, a2q3_b.txt,
and a2q3_c.txt.
This is corrected on the web version now. Thanks to Dylan T. for noticing
this.

--

Please pay attention to the following sentence in Q3: "Your command lines
must work no matter what the current working directory is."
Since you are looking at the files in the /usr/bin directory, you
obviously need to specify this somehow.
A couple other notes regarding this question:
1. Again, "ls" is mandatory command, and no other command.
2. Wildcards are similar but not the same as regular expressions. In
particular, "*" is used in a different way. You are supposed to use
wildcards in Q3.
Q4)
(10 marks) In this question, you will work with the file TomSawyer.txt, which is
available attached in folder. For each of the questions below, you must use the script
command to record your best session into the corresponding file: a2q4_a.txt, a2q4_b.txt,
etc.
(a) Create a soft link in your current directory, with the name TomSawyer.txt which
refers to the above given file.
(b) Use the command grep to list all lines in the file which contain the string Tom.
(c) There seems to be a lot of lines produced in the previous step. Use grep again with the
wc command to print out the number of lines. Your command must print only the
number of lines and nothing else on a line.
(d) Use another pipe of grep and wc commands to print the number of lines in which the

string Tom appears at least twice.


(e) Use another pipe of grep and wc commands to print the number of lines in which the
string Tom appears in a case insensitive way (e.g., as Tom, tom, TOM, toM, etc.).
(f ) Remove the soft link TomSawyer.txt from your current directory.

Remark :
In Question 4, Assignment 2, the phrases "contains a string" and "a word
appears" can be assumed to have the same meaning. For example, the option
"-w" in grep can be used to find words matching a pattern, but you are not
required to use it. For example, if we are looking to find lines
containing the word "public", we would match also lines containing
"publicly" or similar. This is assumed in all sub-questions of question
4.
Q5)
(10 marks) There is a small directory tree set up at the publicly visible
directory:
file attached in folder a2q5 Explore this subdirectory and report any hard or soft link that
you can identify there. Submit your results in a ASCII text file named a2q5.txt. Briefly
explain how you reached your conclusions.

You might also like