Exercise 0.3: Creating Files and Directories

Building Your Workspace

Author

Chuck Nelson

Published

October 28, 2025

Purpose

So far, you have only looked at existing files and folders. A programmer, however, constantly creates new ones to organize projects, write code, and store documentation. In this exercise, you will learn how to create directories with mkdir and empty files with touch (or its equivalent).

What You’ll Accomplish

By the end of this exercise, you will have successfully:

  • Created new directories using mkdir.
  • Created new, empty files from the command line.
  • Built a simple project folder structure.

Creating Directories

The mkdir (make directory) command is used to create a new folder. This command is universal across macOS, Linux, and Windows.

Your Task 1: Make a Directory

  1. First, use cd ~ to make sure you are in your home directory.

  2. Run the following command to create a directory for your practice work:

    mkdir cli-practice
  3. Run ls (or dir). You should now see cli-practice in the list of directories!

  4. Use cd cli-practice to move into your new folder.

Creating Empty Files

Often, you just need to create a blank file that you can edit later. The command for this differs slightly between operating systems.

Your Task 2: Create a File

Follow the instructions for your operating system to create a file named notes.txt inside your cli-practice directory.

The standard command is touch. If the file doesn’t exist, touch creates it. If it does exist, touch simply updates its modification timestamp.

touch notes.txt

In PowerShell, the New-Item cmdlet is the most direct way to create a new file.

New-Item notes.txt

Alternatively, a common shortcut (that also works in CMD) is to use output redirection:

echo. > notes.txt

In the classic Command Prompt, there is no direct touch equivalent. The standard method is to use output redirection to create an empty file.

echo. > notes.txt

This command tells the shell to print nothing (echo.) and redirect that empty output (>) into a new file named notes.txt.

After running the command, use ls (or dir) to confirm that notes.txt now exists in your cli-practice directory.

Verification: Build a Project Structure

Let’s combine your skills to build a standard project folder structure.

  1. Make sure you are inside your cli-practice directory.

  2. Create a main project folder named my-project and navigate into it.

    mkdir my-project
    cd my-project
  3. Inside my-project, create two subdirectories: src (for source code) and docs (for documentation).

    mkdir src
    mkdir docs
  4. Create an empty code file inside the src directory.

    # On macOS/Linux
    touch src/main.py
    
    # On Windows
    New-Item src/main.py
  5. Create an empty documentation file inside the docs directory.

    # On macOS/Linux
    touch docs/README.md
    
    # On Windows
    New-Item docs/README.md
  6. Finally, use ls to see your new src and docs folders. Then, use ls src and ls docs to see the files inside them.

Reflect and Review

ImportantReflection

In your Microsoft Teams Student Notebook, answer the following:

  • What is the command to create a new directory called assignments?
  • What command would you use on your OS to create an empty file called index.html?
  • After creating a file or directory, what command should you always run to verify it exists?
Back to top