$30
COMPSCI 2211b
Software Tools and Systems Programming
Assignment #1
Working With Unix & Linux
Total: 100 Points (5% of Final Grade)
CS2211 - Software Tools and Systems Programming Assignment #1
Learning Outcomes
By completing this assignment, you will gain and demonstrate skills relating to:
• Using ssh and a remote Linux shell.
• Regular expression and grep.
• Navigating files and directories.
• File and directory permissions.
• Symbolic links.
• Piping and redirection.
• Copying, deleting and moving files.
• Using common Linux commands.
Instructions
For this assignment, an electronic submission is required through OWL. This submission should
include a document in PDF format that contains answers for each of the questions listed in the
following sections. Your PDF file should be named “userid assign1.pdf” where “userid” is your
user id. For example, if your UWO e-mail is “dservos5@uwo.ca” your file should be named
“dservos5 assign1.pdf”.
Your answers should be clearly labelled with question and part numbers and include both the
command you issued and the output you received. In addition to your answers, this document
should also contain your full name, student number, UWO user id, the course code, date, and
assignment number.
All Linux commands give must run correctly on the course server (cs2211b.gaul.csd.uwo.ca) in the
Bash shell. A question will only be marked as correct if your output can be replicated on the course
server.
You will be assessed on the following:
• Providing both the command and output for each question.
• Completion of each question correctly.
• Providing a PDF formatted file following the naming convention.
• Including your full name, student number, etc. as described above.
• Assignment submission via OWL.
1 of 4
CS2211 - Software Tools and Systems Programming Assignment #1
Questions
Question 1: ssh and Basic Commands (12 Marks)
(a) Log in to the course server (cs2211b.gaul.csd.uwo.ca) using SSH as you would in the Lab.
Give the full command you gave to log in (no output is required for this question).
(b) Issue a command to print the hostname of the server.
(c) Print a list of users currently logged into the server.
(d) Print the current date.
(e) Print the current working directory.
(f) Using your favourite editor, create a file named helloworld.txt in your home directory
containing the text “Hello World! My name is [Your Name].” where “[Your Name]” is your
real name (only give the command to open the editor/file and not the output for this
question).
(g) Without using an editor, give a command to display the contents of helloworld.txt assuming
your working directory is your home directory. Use relative paths (give both the command
and output).
(h) Without using an editor, give a command to display the contents of helloworld.txt that will
work for any current working directory (give both the command and output).
(i) Make a directory called my text files in your home directory.
(j) Copy helloworld.txt into my text files and name it hello2.txt (in one command).
(k) With your home directory as your current directory, rename hello2.txt (in the my text files
directory) to myhello.txt. Use only one command.
(l) Change your current working directory to my text files and delete myhello.txt (give both
commands).
Question 2: List Command (10 Marks)
On the cs2211b server change your working directory to /usr/bin. This location stores the
executable programs available to users on the server. Using only the ls command, display the
following files names in /usr/bin. Make sure you show both the command and output for each of
the following parts.
(a) Files whose names are exactly 5 characters long.
(b) Files that have g as the second letter.
(c) Files that start with z or q.
(d) Files that end with a number.
(e) Files that have a non-alpha character (not a letter) as the second last character (for example
9, - or . would all be valid second last characters).
2 of 4
CS2211 - Software Tools and Systems Programming Assignment #1
Question 3: Redirection (14 Marks)
Go to your home directory and create a text file called letter.txt. Write 15 lines in this file, where
each line will have just a number from the list 01, 02, 03, ..., 13, 14, 15 in this order.
Use the commands cat, tail or head for part B-F:
(a) Display the content of letter.txt.
(b) Display the last 5 lines of letter.txt
(c) Store the first 4 lines of letter.txt in letter2.txt. Provide the command and the contents of
letter2.txt.
(d) Use the sort command to reverse the contents of letter.txt and both store the result in
letter3.txt and display it to the screen (Hint: Check the manual page for sort and tee). The
command should not alter the contents of letter.txt in anyway.
(e) Explain the difference between cat < letter.txt and cat letter.txt.
(f) Explain the difference between echo cat and cat echo.
Question 4: Pipes (16 Marks)
Give a command for each of the following and show the output you received on the cs2211b server.
Each command should use a pipe. (Hint: Check the manual page for the wc command).
(a) Count the number of users currently on the server (it is ok to count users twice if they are
logged in twice).
(b) Count the number of files in /usr/bin that contain the word “cat” anywhere in the name.
(c) Display the 7th to 11th lines (inclusively) of letter.txt from Question 3 using the head and
tail commands and a pipe.
(d) Display to the screen and store in last10.txt the last 10 lines of .bash history (a file in your
home directory) sorted and with duplicate lines removed (Hint: Check the manual page for
sort). Provide the command and both your output and the contents of last10.txt.
Question 5: grep (18 Marks)
The file /usr/share/dict/words contains a list of dictionary words separated by new lines (one word
per line). Use this file and the grep command find/do the following:
(a) Count the number of words that do not contain the word mil anywhere in them (do not use
the wc command).
(b) Count the number of words that end in ing (do not use the wc command).
(c) Display any word that contains 5 or more vowels in a row. The match should be caseinsensitive (i.e. AAAAAA would match as would AeIou or eeeeeee).
(d) Display any word that starts with the letter z , ends with the letters ly and does not contain
the letter f or t anywhere in the word.
(e) Display any word that starts and ends with the same two letters. For example, toronto, papa
or eraser. You do not need to provide your output for this part.
3 of 4
CS2211 - Software Tools and Systems Programming Assignment #1
Question 6: File Permissions (15 Marks)
On the cs2211b server, accomplish the following tasks and provide the commands you used and the
output you received:
(a) Create a directory called Top1 in your home directory and setup its contents like so:
• Under Top1, create a sub-directories Dir1 and a regular file File1.
• Under Dir1, create directories Dir3 and Dir4.
• Under Dir3, create a regular file File3.
• Under Dir4, create three regular files File4, File5 and File6.
• Under Top1 make Dir2 a symbolic link to Dir1/Dir4.
(b) Set the permissions on the directory Top1 such that all permissions are granted for the owner,
and none are granted for others and group.
(c) Set the permissions on Dir1 such that the owner has all permissions and only read and execute
for others and group.
(d) Dir3 should have all permissions set for the owner, read permission alone for group, and none
for others.
(e) File1 should have read permission alone set for all.
(f) File5 should have execute permission alone set for others and group, and read and execute
permission for the owner.
(g) Display the permissions of Top1 and no other files.
(h) Display the permissions of File4, File5 and File6 with one command.
Question 7: Terminology (15 Marks)
Using the proper terminology (e.g., command, option, option argument, and command argument),
identify the constituent parts of the following UNIX commands (you do not need to explain what
the command does, just identify the parts):
(a) man man
(b) wc -l myfile.txt
(c) ls –all -l /usr/bin/*cat*
(d) grep -icv ?[aeio].* myfile.txt
(e) nano -w -o /gaul/s1/student/1985/dservos5 myfile.txt
Hint: It may be helpful to read the manual pages for these commands.
4 of 4