Homework 1
Basic Unix shell commands
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. Tasks 1 and 2 introduce you to the homework workflow, but only tasks 3 and 4 will be submitted.
Task 1: Log in to attu
Logging into attu
will depend on your computer’s operating system.
- macOS or Linux
- Open the Terminal app.
- Windows
- Open the Terminal app if it is available, otherwise open the PowerShell app.
- ChromeOS
- Go to the ChromeOS settings and, in the Linux section, Turn on Linux. Then, open the Terminal app.
Once you’ve opened the terminal type the command ssh YOUR_CSE_NETID@attu.cs.washington.edu
replacing the capitalized text with your CSE NetID and enter. The first time you connect with the attu
server, it will ask for you to verify the connection, accept the connection by typing ‘y’ and enter (or click the button if it is available). Finally, type your CSE password and enter.
Setup SSH keys on attu for CSE GitLab
CSE GitLab requires SSH keys: computer-generated passwords used to securely authenticate your computer to CSE GitLab. To setup SSH keys on attu
:
- After logging into
attu
, generate an SSH key pair with the commandssh-keygen -t ed25519
- At each prompt, press
Enter
to continue and accept the default settings.- When promoted to “Enter file in which to save the key”, do not enter a file name. Press enter to accept the default file name and location.
- When prompted to “Enter a passphrase”, press enter without entering a passphrase.
- Copy your public SSH key with the command
cat ~/.ssh/id_ed25519.pub
- In your browser, open the SSH Keys user settings. Sign into GitLab using your CSE NetID. Then, paste the public SSH key in the Key field.
- Give it a title like
attu
if it doesn’t already have one and then press Add key.
Task 2: Download the homework files on attu
Task 3 and 4 have deliverable files that you’ll edit on attu
. To get these files, you’ll need to download them from the website and unzip them using the command line. While logged into attu
:
- Create a directory called
cse391
within your home directory. - Change into your
cse391
directory. - Obtain the homework code.
git archive --remote=git@gitlab.cs.washington.edu:cse391/25wi/hw1.git --prefix=hw1/ HEAD | tar -x
You’ll know that you’ve done this correctly if you have several files and directories within cse391/hw1
including task3.txt
and task4.sh
as well as java/
, website/
, animals.txt
, Burrot.java
, numbers.txt
, and song1.txt
.
Task 3: Edit text in the terminal using vim
The following are exercises and questions are meant to help you become more comfortable with editing text with vim from within the terminal.
In task3.txt
, write your answers to the following questions on the indicated lines.
- From the
hw1
directory, how do you openanimals.txt
in vim? - 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?
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. We also recommend getting even more practice by writing the answers to your task3.txt
and task4.sh
files using vim!
Task 4: Linux Bash shell commands
In task4.sh
, for each of the numbered items below, write a single bash command. Use only commands we learned in lecture or noted below in the instructions. Replace the placeholder command, echo "not yet implemented"
with your answer. Some questions may require you to learn new parameters to commands we have discussed: read the man
pages to learn more.
- 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
. Renaming is done using the same command as moving. - Delete the files
diff.html
anddiff.css
. Remember that many commands can accept more than one parameter. - Set the file
MyProgram.java
to have a last-modified date of January 1, 2020, 4:15am. When consulting theman
page fortouch
, the last-modified date is often called a “timestamp” or “STAMP”. Remember that Linux is case-sensitive when you are specifying file or directory names. - List all files with the extension
.html
or.css
in the current directory. Thels
command can accept more than one parameter for listing files. Use a*
(asterisk) as a wildcard 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
. - Copy all text files (ending with
.txt
) from the current folder to thejava
subdirectory. - Using the
diff
command, output the differences betweenlyrics.txt
andlyrics2.txt
. Note that 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>
. The autograder is picky about the order you providelyrics.txt
andlyrics2.txt
to the diff command. - 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
). - Display only the first 7 lines of the file
animals.txt
. Thehead
andtail
commands output only the first or last few lines (respectively) of a file to the terminal.
Submit your work
Submit only your task3.txt
and task4.sh
files to Gradescope.
Since your files are stored on attu
, a remote server, it will take a few extra steps to transfer those files to your personal computer. Use the scp
(secure copy) command, which is like combining ssh
and cp
together. For example, it can be used to copy all files in your hw1
directory that start with the prefix task
to your current directory:
scp YOUR_CSE_NETID@attu.cs.washington.edu:~/cse391/hw1/task* .
This command should be run on your local machine from your terminal app, not from an ssh
session connected to attu
. If you’re currently connected to attu
, use the exit
command to disconnect and return to your local machine. Remember to include the destination, such as .
to indicate the current directory.