Homework 1 - COMP 364

Homework 1 - COMP 364

Assigned in class on Jan 11

Due by class time Jan 18

Late turn in by class time Jan 21 (10% penalty)

Turn in on paper or by email to perkins@mcb.mcgill.ca

1. Setup (10 points)

Perform the following file creating and manipulation tasks. Make sure you do everything described, as the files will be used in the subsequent questions. Using a text editor of your choice, create five text files called "Apple.txt", "Banana.txt", "Grape.txt", "Lemon.txt" and "Orange.txt". In each file, write at least one line of text. It doesn't matter what you write, except that what you write in each file should be different. Modify the permissions on these files as necessary so that you (the user) have read and write permission on "Apple.txt", just read permission on "Banana.txt", just write permission on "Grape.txt", no permissions on "Lemon.txt", and just execute permission on "Orange.txt". In the end, the "pwd" and "ls -l" commands should show you something like:

[perkins][lab2-2][~/HW1] pwd
/home/2006/perkins/HW1
[perkins][lab2-2][~/HW1] ls -l
total 20
-rw------- 1 perkins 17260 23 Jan 11 10:54 Apple.txt
-r-------- 1 perkins 17260 23 Jan 11 10:54 Banana.txt
--w------- 1 perkins 17260 23 Jan 11 10:54 Grape.txt
---------- 1 perkins 17260 23 Jan 11 10:54 Lemon.txt
---x------ 1 perkins 17260 23 Jan 11 10:54 Orange.txt
[perkins][lab2-2][~/HW1] 
Show the result of your "pwd" and "ls -l" commands as proof of completion of this problem. To do this, run the commands and then copy the text from the terminal and paste it into a text file to save for later. You can print this directly or include it in a text file with your other answers, if you are turning in your homework electronically.

2. File permissions (10 points)

a. Which of the files in your HW1 directory can you open using a text editor? In answering this question, please specify which text editor you are using, and explain your answer.

b. Of the files that you can open using your text editor, which can you modify and save? Again, specify which text editor you are using, and explain your answer.

c. Which of the files in your HW1 directory can you copy? (For example, suppose you wanted to copy them to your home directory.)

d. Which of the files in your HW1 directory can you rename (using the mv command)? For any files that you rename, please change the name back to what is was.

e. Which of the files in your HW1 directory can you delete? For any files that you delete, please recreate them afterwards, with the same permissions, for use in the rest of the homework.


3. Exploring "?" and "*" (10 points)

Commands such as cp, mv, rm, and ls do not need to operate on single files or directories at a time. Your task in this question is to figure out what "?" and "*" do on the command line. Working in your HW1 directory, try the sequence of commands shown below. Looking at the results of each command, try to deduce the effect of "?" and "*".

ls
ls Apple.txt
ls Banana.txt
ls ?????.txt
ls ??????.txt
ls ????e.txt
ls ?????????
ls *
ls *.txt
ls *e.txt
ls *n.txt
ls *z.txt
ls A*
ls *a*
ls *e*
ls *r*e*
ls *z*
4. Exploring ">" and ">>" (10 points)

Your task in this question is to figure out what ">" and ">>" on the command line do. Working in your HW1 directory, try the sequence of commands shown below. After each command, examine the contents of the HW1 directory as well as the contents any new files that you may see. Some of these commands will create an error message. That is okay. After performing the commands, and after further experimentation if necessary, explain what ">" and ">>" do.

cat Apple.txt > Temp1.txt
cat Banana.txt > Temp2.txt
cat Apple.txt > Temp2.txt
cat Banana.txt >> Temp2.txt
ls > Temp3.txt
ls -l > Temp3.txt
ls -l >> Temp3.txt
cat Banana.txt >> Temp3.txt
cat Temp3.txt > Temp3.txt
cat Temp3.txt >> Temp3.txt
5. Feedback (No points)

Estimate how long this homework took for you to complete. Was it easy/medium/hard? Was it boring/interesting/fun?