---
title: "Q2 P1"
description: "Have fun with the terminal!"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/q2/problem-sets/p1"
updated: "2026-09-29"
---

:::danger[AI Policy]
Do **not** use any LLM like ChatGPT etc. to do this assignment. You are free to do a google search to learn about commands.
:::

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).

:::note[The bash shell]
The "flavour" of shell that runs on Ubuntu is called ***bash***.
:::

Here are some tips before you begin:

- Repeatedly use `pwd` and `ls` to check where you are and what files are present in this directory
- Run `man` and `--help` for learning more about a command
- Keep the [**Terminal** Cheatsheet](wiki:89375af9dac2) handy

### Download

Go ahead and download [this zip file](/files/cs17-archive.zip). 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:

```bash
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.

:::note[Hint]
You might have to use an **absolute path** to point to the `zip` file.
:::

### 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:



1. Find the `competitions` directory
  - What is its *parent* directory? 
  - What is the absolute path for this folder?
2. Look for `scrap.txt` file
  - What is its *parent* directory?
  - What is the **absolute path** of this file?
  - **How many lines and words** does this file contain?
3. Look for folders that contain images
4. Print the contents of the `README.txt` file 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:

```bash
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:

1. Print only the **first 10 lines** of `README.txt`. Then print only the **last 5 lines**.
2. 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-assignment` directory:
  - `gallery`
  - `backup`
  - `sorted`
- You can use `ls` to check if the folders were correctly created
- Inside the `sorted` directory create a folder named `notes` 
- Inside the `gallery` directory, create a folder named `competition-2026`

### Move Things



Now that we have the folders in place, let's start arranging files. Here is what you need to do:

1. List every `jpg` file in the "Unsorted Camera Dump" folder (try to use absolute path + tab completion instead of typing the full filename).
2. **Move** every one of these `jpg` files into the `gallery` folder you created in the last step.
3. But wait, there is more, `png` is also an image, move all `png` files too into the `gallery` directory.
4. **Move** `camera-settings-backup.txt` into `sorted/notes`.
5. Move the 3 competition entries (inside `inbox/competitions/photography-competition-entries-2026`) into `gallery/competition-2026`.
6. Create a **copy** of **every** `txt` file in `logs` folder into the `backup`.
7. **Move** `old-notes.txt` (locate it in your assignment folder first) into `sorted/notes`. Then **rename** this file to `last-year-notes.txt`.
8. **Copy** the Term 2 report into `sorted/notes`. The original must stay in `documents/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:

1. Find and delete the `scrap.txt` file. Its parent directory will then become empty, delete that too.
2. Delete the "*Unsorted Camera Dump*" and `old-phone-photos` directory.
3. Delete the `temp` folder **along with all its contents**, it had done its job a long time ago.
4. Delete `competitions/photography-competition-entries-2026` folder.

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`. 

1. Print all the lines in this file that contain the word `present`. How many such lines are there?
2. 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):

```plaintext
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.

1. Print the attendance for the **first** club day. (Remember, the first line of the file is the column names.)
2. Print the attendance for the **last** club day. Who was absent?
3. Create a new file `last-day.txt` in 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:

```shell
 $ cowsay "CS17 Army ROCKS" # command
 _________________
< CS17 Army ROCKS >
 -----------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
```

As you can see, whatever **argument** you pass, it will print a **cow say**ing 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 &lt;replace-with-*your-name*&gt;!**" into this file. Wait, there is one more thing, you have to **add** something more to the file, `cowsay` "**Bye from &lt;replace-with-*your-name*&gt;!**".



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:

```bash
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

:::caution[Review your work]
Before proceeding with submission, please make sure you have reviewed each task carefully.
:::

Submit `terminal-assignment.zip` from your [student dashboard](https://portal.cs17.org/dashboard).