In this assignment you will practice working with the command-line, as well as using git and GitHub to manage code files—the same as you will be doing for the rest of the quarter.
By completing this assignment you will practice and master the following skills:
- Creating repositories on GitHub and cloning these repositories to a development machine
- Using git to add new files, commit changes, and push those changes back to GitHub
- Formatting documents using Markdown
- Using common Bash utilities to manipulate files and folders
- Reading Bash manual pages and identifying shell utility parameters
To complete this assignment, follow these steps. If you get stuck (particularly with installation issues), ask your TA or the professor for help!
First, make sure you've completed the "Getting Started" steps on the course Canvas page; having the development software (particularly git and Bash) installed is a requirement for the remainder of the steps.
Each of your assignments in this course will be completed in a private code repository provided by GitHub Classroom. You can create the repo for this assignment by visiting the following link:
You will need to accept this assignment to create your code repo. This repo will have the name
infx598i-s17/a1-git-and-cli-yourusername, and you can view it online at
yourusername with your GitHub user name).
fork this repository!
After you've accepted the assignment,
clone the repo to your local machine so you can edit the files. Make sure you don't clone it inside another repo!
There are a couple of starter files included: a
README.md file with some information about the repo, and a hidden
.gitignore file you will be working with.
For this step, you'll practice with the basic "edit-commit-push" cycle for tracking code changes with git. You will do this by editing the provided
README.md file to include information about the author of the repo (that's you!) as well as
Add a section to the README with some information about yourself. This section should include the following content:
A 2nd-level heading with the text "About the author"
A paragraph (1 sentence) giving your name and graduate program. Your name should be in bold, and the name of the graduate program should be in italics. The name of the graduate program should also be a hyperlink to the program's webpage.
You should modify this document in a text editor like VS Code, which you can also use to preview the output and make sure it looks correct.
After you make these changes,
commit your changes to the document.
"Add author info" is a good commit message when you're done. You can then
push the changes to GitHub and view them online.
Next, add a section to the README with some information about a command-line utility that has not been explicitly discussed in class or in the learning module (you'll need to do some outside research--remember, we're learning how to learn!).
grep are good options to look up that you'll use later in this assignment, but if you're feeling ambitious check out
awk. This section should include the following content:
Another 2nd-level heading with the name of the command you're describing.
Another paragraph giving a 1-2 sentence explanation of what the utility does.
A single example of how the command is used, formatted as a code block. This example should include at least one option.
A list of at least two (2) useful options to the command, including the one used in the above example.
Again, remember to
push your changes.
"Add command info" is a good commit message when you're done.
Step 3. Command-Line Practice
Now that you've got the hang of git, it's time to get more practice with the command-line! For this step, you'll practice with some basic file shell utilities, and will need to save your command-line session to a file. The easiest way to do this is to simply copy-and-paste the terminal contents into a
practice-session.txt file (e.g., created and opened with VS Code) saved in your assignment repo.
On a Mac or Linux, it is also possible to record a shell session using the
script utility (e.g.,
script practice-session.txt). Then you just work with the shell as normal, using the exit command to stop recording when finished.
From the command-line, you should perform the following steps:
Display the current working directory. If the current directory is not your repo, use
cd to change to it and then display the current working directory again to demonstrate that you're in the right place.
Display your computer's
PATH) is a system-level environmental variable that keeps a list of directories where command-line programs and utilities may be found, so that the command shell knows where to look for the program to run. So if you tell the shell to run the
git command (e.g., with
git status), the shell will look for an executable file called
git on each directory listed in the path, in order. Effectively, this acts as a set of "shortcuts" instead of needing to specify the full location of the program to run.
Variables in Bash are written with a leading
$. So if you had a variable called
HOME_DIR, you would refer to it as
$HOME_DIR (e.g., in
Display the contents of the hidden
.gitignore file in the repo's "root" directory.
.gitignore file is used to tell git to "ignore" certain files and never commit them. It contains a list of files and folders to ignore.
Using the command line, make a new folder called
sonnets inside your repo.
Change directory into the
sonnets folder and display its contents to verify that the folder is empty.
Using the command line AND WITHOUT CHANGING DIRECTORIES, copy the hidden
.gitignore file from the repo's "root" folder into the
sonnets folder. Remember, you can refer to the "parent" folder (up one level) as
.. (two dots).
Display the contents of the directory to verify that the file copied. Use the
-a option to show all files (including hidden ones like
Copy the contents of your terminal (from command 1 above on) and save it in a file
practice-session.txt inside your repo's root directory (not in the
It's okay if there are extra commands or mistakes in your session log; we'll just be looking that you managed to perform the required steps eventually!
commit your shell log, as well as the new
.gitignore file you created (which will cause the empty
sonnets folder to be committed as well).
"Add session recording" is a good commit message. We will be looking for a commit for this specific step. You should push this commit to GitHub if you want to keep things backed up.
Finally, in this step you'll practice using the command-line to do some actual data processing and simple "programming".
You do not need to record your shell session for this step. Instead, you'll be creating a simple shell script that will encapsulate all of your commands into a single file (like a recorded macro or shortcut).
sonnets/ folder you created, create a new file called
analysis.sh (note the
.sh extension!). You don't need to do this using the command-line; you can and should edit the file in a graphical editor like VS Code. You can then run the script with:
When run, your script should perform the following steps:
Download the text of Shakespeare's Sonnets from Project Gutenburg (http://www.gutenberg.org/files/1041/1041.txt). You should redirect the downloaded text to a file called
sonnets.txt in the same folder as the
Remove extraneous content from the file, leaving only the numbers and text of the sonnets. This means removing the Gutenburg header (the first 45 lines), the copyright information at the bottom, as well as the leading blank spaces before every line.
You can use the
tail commands to output only certain lines of a file. The
cut utility is good for only printing certain characters of a line.
You'll need to look up how these command work; check the manual pages and search around for examples! Experiment until you figure out what you need. If you get stuck, ask for help!
A good tip is to think about using one of these commands to process the file, and then piping that output into the next command for further processing. For example, you might start by using
tail to only output the content after the header, and then pipe those results to
head to only output the content before the copyright. You can temporarily redirect the output to a file (e.g.,
content.txt) which can be opened in VS Code, allowing you to inspect your work and make sure you're getting the right content. Just make sure your script cleans up (removes) this extra file when you're done (or modify your code so you use pipes instead).
Once you've isolated the content, your script should split each sonnet into its own file (containing the number and the sonnet text). Each file should have a name like
You are not required to specify file extensions (e.g.,
.txt) for these split files, but you can search for how to do so for extra credit.
As you're testing your script, note that you can have it automatically "clean up" old files at the beginning by using the
Your script should first analyze the individual sonnets to discover which has the greatest number of words in its 14 lines. You should count the words in each file, and then sort the results in descending order. Your script should redirect this ordered list to a file
Finally, you should perform the following searches on the split sonnet files (and only the split sonnet files):
- Search all the individual sonnet files for the word
"truth", redirecting the results to a file
- Search only the individual sonnet files ending in
s for the word
"love", redirecting the results to a file
commit your shell script to your git repo, as well as the analysis result files (
love.txt). DO NOT commit all 154 sonnet files (you can even add them to the
.gitignore file if you want to make sure they aren't stored in the repo).
"Add sonnet analysis" is a good commit message.
The last step of all assignments is to fill out a Submission questionnaire with details about your submission. This will help us in evaluating your assignment (and improving them in the future!). Please take a minute to do so.
- You will need to be signed into your UW Google account to access the form. Make sure you have activated your account. If you have problems signing in, try opening an Incognito/private browser window and using that. If that still doesn't work, check in with us!
In order to submit assignments in this class:
Confirm that you've successfully completed the assignment (e.g., that you have filled in the README, saved your session history, and produced your shell script).
commit the final version of your work, and
push your code to your GitHub repository.
Submit the URL of your GitHub Repository as your assignment submission on Canvas (this page, at the top).