You added a very powerful skill to your tool belt recently: working with the terminal. It is now time to put it into practice and become fluent with running commands through the shell. You might be tempted to use the user interface with the mouse, but please refrain and stick to the terminal (and keyboard).
Here are some tips before you begin:
- Repeatedly use
pwdandlsto check where you are and what files are present in this directory - Run
manand--helpfor learning more about a command - Keep the Terminal Cheatsheet handy
Download
Go ahead and download this zip file. The files in this ZIP are a mess. Your task is to clean it up by creating proper directories, files, and more.
Unzip
Your first task is to unpack the ZIP file you just downloaded. unzip is a command that will help you do just that. Here is how to use the command:
unzip archive.zip # unpack a zip file into the folder that you are in (pwd)
Unzip the cs17-archive.zip file in your Desktop directory. This will create a new folder named cs17-archive. Rename this folder to terminal-assignment. This is your assignment folder: every task below happens inside it.
Peek Around
Before we begin with the tasks that modify the files, you should navigate through the directories, and see what is already there. Start by doing the following:
- Find the
competitionsdirectory
- What is its parent directory?
- What is the absolute path for this folder?
- Look for
scrap.txtfile
- What is its parent directory?
- What is the absolute path of this file?
- How many lines and words does this file contain?
- Look for folders that contain images
- Print the contents of the
README.txtfile and note down the entire directory structure in your notebook (you may not write full file names). This will help you with the tasks ahead.
Head and Tail
Some files are too long to read comfortably on one screen. Two new commands help you look at just a part of a file:
head -n 5 notes.txt # print only the first 5 lines of a file
tail -n 5 notes.txt # print only the last 5 lines of a file
Try them out:
- Print only the first 10 lines of
README.txt. Then print only the last 5 lines. - Print only the first line of
club-members-attendance-register.txt. What are the column names?
New Directories
- Using the correct command, create three new folders in the
terminal-assignmentdirectory:gallerybackupsorted
- You can use
lsto check if the folders were correctly created - Inside the
sorteddirectory create a folder namednotes - Inside the
gallerydirectory, create a folder namedcompetition-2026
Move Things
Now that we have the folders in place, let's start arranging files. Here is what you need to do:
- List every
jpgfile in the "Unsorted Camera Dump" folder (try to use absolute path + tab completion instead of typing the full filename). - Move every one of these
jpgfiles into thegalleryfolder you created in the last step. - But wait, there is more,
pngis also an image, move allpngfiles too into thegallerydirectory. - Move
camera-settings-backup.txtintosorted/notes. - Move the 3 competition entries (inside
inbox/competitions/photography-competition-entries-2026) intogallery/competition-2026. - Create a copy of every
txtfile inlogsfolder into thebackup. - Move
old-notes.txt(locate it in your assignment folder first) intosorted/notes. Then rename this file tolast-year-notes.txt. - Copy the Term 2 report into
sorted/notes. The original must stay indocuments/reports.
Clean Up
We moved files into relevant folders. But that left behind unused empty folders and some useless files too. Let's remove those:
- Find and delete the
scrap.txtfile. Its parent directory will then become empty, delete that too. - Delete the "Unsorted Camera Dump" and
old-phone-photosdirectory. - Delete the
tempfolder along with all its contents, it had done its job a long time ago. - Delete
competitions/photography-competition-entries-2026folder.
Much better. You can now clear the screen if you have not already done so.
Search
Start by locating the file named club-members-attendance-register.txt.
- Print all the lines in this file that contain the word
present. How many such lines are there? - Print all the lines in this file that contain the word
absent. How many lines?
Now, create a new file attendance.txt in the same folder as the above file and add the following to attendance.txt file:
- The text "Present"
- Number of lines with the word
present - The text "Absent"
- Number of lines with the word
absent
At the end, the file contents should look something like this (example numbers):
Present
14
Absent
20
First and Last Day
The attendance register is sorted by date: the oldest club day is at the top and the latest one is at the bottom. Each club day has 6 lines, one per member.
- Print the attendance for the first club day. (Remember, the first line of the file is the column names.)
- Print the attendance for the last club day. Who was absent?
- Create a new file
last-day.txtin the same folder that contains only the 6 lines of the last club day.
Install New Commands
There are a lot of different commands that come out of the box with your default shell software: ls, zip, mkdir, etc. But that is not it: people all over the world have built different shell commands (programs) that you can install and use. One such program is cowsay, which as the name implies, will do this:
$ cowsay "CS17 Army ROCKS" # command
_________________
< CS17 Army ROCKS >
-----------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
As you can see, whatever argument you pass, it will print a cow saying that piece of text 😂
If you try to run the above command, it will tell you that the command is not found, because it is not installed by default on your computer. Just like you installed Google Chrome from the internet, you will have to install cowsay. You don't need to leave your terminal to do this. You can just run:
sudo apt install cowsay
Try to use the command yourself with some text!
Task
Create a surprise.txt file at the root of your assignment directory and redirect the output of cowsay with "Hello from <replace-with-your-name>!" into this file. Wait, there is one more thing, you have to add something more to the file, cowsay "Bye from <replace-with-your-name>!".
So, at the end, the file should contain two of them.
History
Promise, this is the last one :)
You have to create a new history.txt file at the root (i.e. directly in that folder, not inside a nested folder) of your assignment folder. Then fill this with the last 200 commands from your history.
The history command prints every command you have ever run, which is a lot more than we need. To keep only the last 200 lines, you can send the output of one command into another command using the pipe (|) symbol:
history | tail -n 5 # print only the last 5 commands from your history
Change the number and redirect the result into history.txt.
Re-ZIP
It is time to compress our revamped directory, use the zip command (find how to use it) to compress the terminal-assignment directory, with the name terminal-assignment.zip.
Submission
Submit terminal-assignment.zip from your student dashboard.