CSE 333 - OPERATING SYSTEMS Programming Assignment # 1

Transcription

CSE 333 - OPERATING SYSTEMS Programming Assignment # 1
CSE 333 - OPERATING SYSTEMS
Programming Assignment # 1
DUE DATE: 05/11/2014 - 23:59 (No extension)
1.
(20 pts)Write a shell script that finds out the n largest files in a directory. Your program
will require one or two arguments. If one argument is given, this argument will be the
number of files (n) and it will list the n largest files in current directory. If we want to do
the same operation on a directory other than the working directory, the second argument
of the program will be provided. You are required to consider necessary argument and
error checking. The output of your program should be as in the following example.
Ex:
$ ls –l /home/std/Desktop
total 2328
-rw------1 std std 152144 Jun 20 2005 alice-in-wonderland.txt
-rw------1 std std 82140 Jun 20 2005 barleby-scrivener.txt
-rw------1 std std 13421 Jun 20 2005 calaveras-county.txt
-rw------1 std std 13107 Jun 20 2005 cask-of-amontillado.txt
-rw------1 std std 635 Jun 20 2005 french.txt
-rw------1 std std 496769 Jun 20 2005 hawthorne.txt
-rw------1 std std 172541 Jun 20 2005 looking-glass.txt
drwx-----14 std std 476 May 25 2007 shakespeare
-rw------1 std std 192710 Jun 20 2005 song-of-hiawatha.txt
-rw------1 std std 35238 Jun 20 2005 trees-and-other-poems.txt
$ ./myprog1.sh 1 /home/std/Desktop
496769 hawthorne.txt
$ ./myprog1.sh 2 /home/std/Desktop
496769 hawthorne.txt
192710 song-of-hiawatha.txt
$ cd /home/std/Desktop
$ ./myprog1.sh 3
496769 hawthorne.txt
192710 song-of-hiawatha.txt
172541 looking-glass.txt
2.
(10 pts)Write a shell script that takes a character set (pattern) as an argument and list the
modification dates (in chronological order) of files whose names contain the given
pattern in your current directory. Please note that you should consider all possible error
checking and related warnings.
Ex:
$ ./myprog2.sh sun
The file sun1.txt was modified on 2014-09-01 at 01:26.
The file morning-sun.txt was modified on 2014-10-01 at 02:53.
The file evening-sun.txt was modified on 2014-10-01 at 02:55.
The file sun2.txt was modified on 2014-10-16 at 19:10.
3.
(20 pts)Write a shell script that takes a character set (pattern) as an argument and list the
words which include the given pattern. If one argument is given, search the word in all
files in your current directory. If we want to do the same operation on a directory other
than the working directory, the second argument of the program will be provided. The
list should be in alphabetical order and should ignore the case. You can ignore the files
in the sub-directories. Please note that you should consider all possible error checking
and related warnings. The output of your program should be as in the following
example.
Ex:
$ ./myprog3.sh
deerfood
food
fooder
food
foodful
foodless
foodlessness
$ ./myprog3.sh
twas
miltwaste
twas /home/std/Desktop/dict
outwash
twas
outwaste
twasome
$ ./myprog3.sh a*rum*
Agarum
anoestrum
alabastrum
antirumor
alarum
antiserum
ambulacrum
antistrumatic
Anatherum
antistrumous
androphorum
antrum
4.
foodstuff
foody
nonfood
Aplectrum
archicerebrum
arcocentrum
Arrhenatherum
Arum
arumin
unfoodful
Asarum
Ascyrum
aurum
autoserum
(20 pts)Write a shell script that prints to the screen a sequence of numbers based on the
command line arguments. There might be different numbers of arguments:
 Three arguments: START STOP STEP
 Two arguments: START STOP (assume step is 1)
 One argument: STOP (assume start and step are both 1)
You may assume STEP is always positive. If STOP is smaller than START you
should subtract STEP at each interval, and if STOP is greater than START you
should add STEP at each interval. Please note that you should consider all possible error
checking and related warnings (If no/too many arguments are given, you should print
out a message and exit with a failure value).
Ex:
$ ./myprog4.sh
100
83
66
49
32
15
-2
-19
100 -20
$ ./myprog4.sh
10 20 4
17
10
14
18
$ ./myprog4.sh
Usage: ./myprog4.sh <start> <stop> <step>
./myprog4.sh <start> <stop>
./myprog4.sh <stop>
5.
# go from start to stop by step
# assume step is 1
# assume start and step are 1
(10 pts)Write a shell script that reads a sequence of integers from the standard input and
then prints out the total. You may assume that each number appears on its own line and
is an integer and that the total will not cause any overflow. The output of your program
should be as in the following example.
Ex:
$ ./myprog5.sh
10
16
-3
Total is 23.
$ ./myprog4.sh 100 -20
Total is 324.
6.
17
| ./myprog5.sh
(10 pts)Write a shell script that by default report the total number of lines in all of
the files in the current working directory (recursively). Your program should support
optional arguments. If only one argument is provided, that will be used as a pattern for
the files. If a pattern is specified and any other argument is supplied, use each of those as
the directories to recursively examine. The output of your program should be as in the
following example.
Ex:
$ ./myprog6.sh
Total is 1021.
$ ./myprog6.sh *.java
Total is 324.
$ ./myprog6.sh *.java courses/cse141 courses/cse142
Total is 10000.
Notes:
 You are required to consider all necessary error checking for the programs.
 No late homework will be accepted.
 In case of any form of copying and cheating on solutions, all parties will get ZERO
grade. You should submit your own work. In case of any forms of cheating or
copying, both giver and receiver are equally culpable and suffer equal penalties.
 You should work with a partner. Your partner will not be changed throughout the
semester.
 You are required to submit a 2-pages report and commented code (via e-mail:
[email protected]).
 Your report should include explanations about implementations. Your
implementation detail should be provided in the source code comment.
 Please put your COMMENTED source codes and project report in a zip file and
make sure that your zip file contain s your names and student IDs!