BIL 461 Summer 2015 Homework 1 The homework answers and

Transcription

BIL 461 Summer 2015 Homework 1 The homework answers and
BIL 461
Summer 2015
Homework 1
The homework answers and code must be submitted to our Teaching Assistant Cansin Bayrak by email to
[email protected] by Friday, May 22 before 12:30.
Subject of the email should say “BIL461 Homework 1”. Name your homework directory as
“YourFullName-HW1”. Before submitting, put all your files in and zip your homework directory, and
email a single zipped file as attachment. You will lose %5 of your grade if you deviate from this
submission format. Remember also that for programming components, your code should be fully
documented.
For each of the steps in Part 1 through Part 5 below, you will run some Unix commands, and answer
questions. Type your answers in a file called Answers (text file or word document). For each step, run
the command, copy-paste the part of the shell including the line you ran the command and any output it
produces into your answers file, and answer any questions given. Submit your answers file with the rest
of your homework files. Part 6 requires you to write a C program, and you will submit your source code
(.h and .c files).
Part 1: Practice moving around the file system and paths
1. Enter the pwd command. What happens?
2. Which shell are you using? How do you find out?
3. Enter mkdir BIL461
4. Enter the command cd BIL461. What happens?
5.
Enter the cd command. What happens?
6.
Enter cd .. What happens?
7.
Display the content of this directory. What command did you use?
8. Try the command cd / Display the content of this directory. Which directory is this?
9. Repeat step 4. Do you know another possibility to get where you are now?
10. Display your search path.
11. What is the absolute path to your home directory?
12. Go to the tmp directory in /var using only one command.
13. Now go to bin in /usr using only one command.
What command did you use?
Part 2: Practice with the help utilities
1. Read man intro
What happens?
2. Read man ls
List some options available to ls that we did not cover
Part 3: Practice copying files.
1. Create two new directories in your home directory called TEST1 and TEST2
2. Change your working directory to TEST1 directory and create four files called test1.c test2.c
in1.txt in2.txt
3. List the files in alphabetical order. What command did you use?
4. Copy the files with .c extension to TEST2, list the files under TEST1 and TEST2
5. Change to your home directory. Delete the TEST1 directory and its entire content using a single
command. What command did you use?
Part 4. Practice with wildcards
Suppose your working directory contained the following files:
backgammon backpacking
biking
blackjack
baseball
boxing
basketball
bridge
camping
canoeing
checkers
crossword
dancing
eating
chess
fencing
fishing
football
golf
hearts
hiking
karate
poker
rugby
sailing
skiing
softball
swimming
team1
team2
team3
team4
teamA
teamB
teamM
teamW
1.
2.
3.
4.
teamC
teamX
teamD
teamY
How would you use cat to show the contents of the files ending in ing
How would you list any files containing x or X (in this case boxing and teamX)?
How would you show the contents of files with names containing o?
How would you show the contents of the files backgammon, backpacking, and blackjack using
just one command?
Part 5. Miscalleneous
1. What does the following command do? Explain it clearly. You may have to look at the man pages
to see what the various options are doing.
ls -as | sort -nr | head -5 > out.txt
2. Using your favorite editor, type the following into a text file called text.in
abcd
efgh
abcd
efgh
abcd
ef
ef
3. What command can you use to display text.in in alphabetical order?
4. How can you remove adjacent duplicate lines from text.in?
5. How would you set the file permissions for text.in so that user gets read, write and execute
access, group gets only read and execute access, others get only read access.
Part 6. C Programming
Write a C program that implements a new version of Unix's diff command (to be called newdiff.c).
Given two text files file1.txt and file2.txt,
newdiff -flag file1.txt file2.txt
should return



Zero (0) if the two files are exactly identical.
-1 if either one of the files is missing or cannot be opened.
A positive integer indicating
o the number of characters that are different in the two files (if -c flag is used)
o the number of words that are different in the two files (if -w flag is used)
o the number of lines that are different in the two files (if -l flag is used)
You will need to use C's string related functions (in string.h) and file I/O functions.