Due Tuesday 10/08 at 1:00 pm. No late submissions accepted.
Submission: Gradescope
Specification: Spec
This assignment focuses on using the bash shell to execute common Unix commands. Some of the questions are Unix commands you must figure out, and others are general questions about the particular Linux system you are using.
Tip
Unless otherwise specified, each question can be answered entirely by using commands discussed in class (i.e. shown in the lecture slides from the first week). You may use other commands if you like, but you should generally constrain yourself to those from lecture; ask the instructor if you are unsure whether a particular command is allowed.
For Task 1 and Task 2, there is nothing to submit. For Tasks 3 and 4, you will fill out the provided task3.txt
and task4.sh
template files and submit your responses to Gradescope.
To calculate your final score on this assignment, sum the individual scores from Gradescope.
- if your
score
is between[0, 1)
, you will get0
points - if your
score
is between[1.0, 1.5)
, you will get1
point - if your
score
is between[1.5, 2]
, you will get2
points
Task 1: Log in to a Linux environment¶
First, log in to a Linux environment.
There are several options to choose. Roughly speaking, we suggest (in order):
- log in remotely to a Linux computer operated by UW (e.g.
attu
,vergil
,linuxNN
,ovid
,cancun
,calgary
) - download and install the CSE virtual machine image
For detailed instructions, we’ll refer you to the Working At Home page. If you run into problems logging in to a Linux environment, please contact the course staff for more help.
Task 2: Download and open the homework files¶
Task 3 and 4 have deliverable files that you’ll edit within your Linux environment. To get these files, you’ll need to download them from the website and unzip them - all using the command line.
Do the following:
- Create a directory (folder) called
391
within your home directory - Download the
hw1.zip
and save it within your new391
directory. You should do this via the command line, by using the following command (with391
as your current directory):wget https://courses.cs.washington.edu/courses/cse391/24au/homework/hw1/hw1.zip
- Unzip the
hw1.zip
file’s contents into a new folder. You should do this via the command line, by using the following command (with391
as your current directory):unzip hw1.zip
You’ll know that you’ve done this correctly if you have several files and directories within 391/hw1
. Importantly, this should include task3.txt
and task4.sh
(which you’ll turn in) as well as java/
, website/
, animals.txt
, Burrot.java
, numbers.txt
, and song1.txt
.
Task 3: Getting Comfortable with a Text Editor¶
The following are exercises and questions are meant to help you become more comfortable with a text editor that is built into the command line. You can choose either vim
or emacs
. It does not matter which editor you choose, but we recommend that you pick one and stick to learning it for the remainder of the quarter.
Tip
After you pick a text editor, take a look at the reference cards that editor.
While the answers to the questions themselves are relatively easy to find by simply looking them up, the real learning will come from you actually practicing these commands yourself. While we wonβt be able to know whether youβve really been practicing, this is not for our benefit, itβs for yours. We also recommend getting even more practice by writing the answers to your task3.txt
and task4.sh
files using this editor! π
Write your answers to the following questions on the indicated lines in the provided task3.txt
file in the hw1
folder.
- Which text editor are you choosing to use?
emacs
orvim
? - From the
hw1
directory, how do you openanimals.txt
in the text editor of your choice? - Practice moving your cursor around the file. Move your cursor up, down, left and right. Assuming your cursor is at the beginning of the first line of the file, what are the keystrokes to move your cursor to the end of the line and append the text
"animal"
? - Next, what are the keystrokes to move your cursor back to the front of the line and insert the word
"animal"
? - How do you save your changes to the file?
- How do you exit the file and return back to your command line prompt in the shell?
Task 4: Linux Bash shell commands¶
For each of the numbered items below, determine a single bash shell command that will perform the operation(s) requested.
Warning
In particular, you should not use features we have not learned in class (such as multi-statement joining operators like |
, &&
, ||
, or ;
- which we’ll learn about in the next two weeks).
Tip
Several questions require you to learn new parameters to commands we have discussed; find these out by looking at man
pages for that command.
To test your commands, you should have unzipped hw1.zip
into the current directory. You can assume you are in the hw1
directory when doing these problems.
In response to each question, you will provide the command that will perform the task described, not the output that the command produces. Write your commands on the indicated lines in the provided task4.sh
file in the hw1
folder. For each of your answers, replace the line echo "not yet implemented"
with your solution.
For example if a question asked you to list all the files in the current directory you would change:
function problem0 {
# Type your answer to problem #1 below this line
echo "Not yet implemented"
}
function problem0 {
ls
}
- Copy the file
MyProgram.java
from the current directory to thejava
subdirectory. - List the files in the current directory, in “long listing format”.
- List all files, including hidden files, in the
/var
directory, in reverse alphabetical order and long listing format. (Notice the slash in the directory!) -
Rename the file
Burrot.java
toBorat.java
.Hint: Renaming is done using the same command as moving.
-
Delete the files
diff.html
anddiff.css
. Note that your answer must be a single command and not multiple commands.Hint: Many commands can accept more than one parameter.
-
π Self Discovery: Set the file
MyProgram.java
to have a last-modified date of January 1, 2020, 4:15am.Hint: Look at the
man
page fortouch
. In particular, the last-modified date is often called a “timestamp” or “STAMP”.Also note: Linux is case-sensitive when you are specifying file or directory names.
-
π Self Discovery: You can use a
*
(asterisk) as a “wild-card” character to specify a group of files. For example,*foo
means all files whose names end withfoo
, andfoo*
means all files whose names begin withfoo
. You can use a wildcard in the middle of a file name, such asfoo*bar
for all files that start withfoo
and end withbar
.List all web page files (files whose names end with the extension
.html
or.css
) in the current directory. Note that thels
command can accept more than one parameter for what files you want it to list (e.g.ls website/ java/
). -
Copy all the text files (files whose names end with
.txt
) from the current folder to thejava
subdirectory. -
The
diff
command outputs the differences between two files. Output the differences betweenlyrics.txt
andlyrics2.txt
.Notice the line differences from the first file argument begin with a left-pointing caret
<
and line differences from the second file argument begin with a right-pointing caret>
. Gradescope will be picky about the order you providelyrics.txt
andlyrics2.txt
to the diff command.Fun Fact: we use the diff command in the Gradescope autograder!
-
π Self Discovery: The
cat
command outputs the contents of a file to the terminal. Theless
command outputs the contents of a file to the terminal, page by page, pausing for you to press a key.Use whichever command is best suited to display the contents of the file
lyrics.txt
. -
Display the contents of all files whose names begin with
song
and end with the extension.txt
(e.g.,song1.txt
andsong2.txt
). Write a single command that displays all their contents concatenated. -
π Self Discovery: The
head
andtail
commands output only the first or last few lines (respectively) of a file to the terminal.Display only the first 7 lines of the file
animals.txt
from the current directory on the terminal.
Appendix: Transferring files to your Local Machine from attu¶
If you are working in an ssh
session connected to attu
, you will likely want to transfer files from attu
to your local machine so you can turn them into Gradescope. If you are working from the Linux VM, you have access to a browser within the VM. To transfer files, you can use the scp
(secure copy) command which is like ssh
+ cp
together! scp
uses the following syntax:
scp <source-location> <destination-location>
Warning
This command should be run on your local machine from your Terminal application, NOT from within an ssh
session connected to attu
.
For example, if you wanted to copy foo.txt
from your home directory on attu to your current directory on your local machine, you would use the command:
scp <your_cse_id>@attu.cs.washington.edu:~/foo.txt .
Warning
Be careful not to forget the .
at the end of that command, which is your current directory.
If you instead wanted to copy the file foo.txt
from your current directory on your local machine to your 391
folder in your home directory on attu
, you would use the following command:
scp foo.txt <your_cse_id>@attu.cs.washington.edu:~/391