Lesson 2.3

Building Structure

5 minutes

So far you’ve been exploring files and directories that already exist. Now let’s learn to create your own. These commands are the building blocks your AI tools use every time they scaffold a new feature or set up a project.

mkdir — Create a Directory

What it does: Creates a new empty directory.

Try it now: Type mkdir ~/projects/my-app/src/features

Then confirm it exists: ls ~/projects/my-app/src

You should see the new features directory listed.

mkdir -p — Create Nested Directories

What if you need to create a whole path of directories that don’t exist yet?

Try it now: Type mkdir -p ~/projects/my-app/src/features/auth/tests

Without -p, this would fail because auth and tests don’t exist yet. The -p flag tells mkdir to create every directory in the path as needed — parent directories and all.

Try it: Run ls -R ~/projects/my-app/src/features to see the full nested structure you just created.

When AI Tools Use mkdir -p
When an AI coding tool creates a new component, it often runs something like mkdir -p src/components/Dashboard before writing the files. The -p flag ensures the command won't fail even if some directories already exist.

touch — Create an Empty File

What it does: Creates a new empty file (or updates the timestamp if the file already exists).

Try it now: Type touch ~/projects/my-app/src/features/auth.js

Confirm it: ls ~/projects/my-app/src/features

You’ll see auth.js — an empty file, ready for you (or your AI tool) to write code into.

You can create multiple files at once:

Try it now: Type touch ~/projects/my-app/src/features/login.js ~/projects/my-app/src/features/signup.js

Then ls ~/projects/my-app/src/features to see all three files.

tree — Visualize the Structure

What it does: Shows the directory structure as a visual tree.

Try it now: Type tree ~/projects/my-app/src

You’ll see something like:

src
├── components
│   ├── App.js
│   └── Header.js
├── features
│   ├── auth
│   │   └── tests
│   ├── auth.js
│   ├── login.js
│   └── signup.js
└── index.js

tree is much more readable than ls -R for understanding project layout. It’s one of the best commands to run when you’re getting oriented in a new codebase.

Summary
mkdir — create a directory
mkdir -p — create nested directories (won't fail if they exist)
touch — create an empty file
tree — visualize directory structure as a tree

Practice

Try building a small project structure from scratch:

  1. mkdir -p ~/projects/my-app/src/utils — create a utils directory
  2. touch ~/projects/my-app/src/utils/helpers.js — add a file to it
  3. tree ~/projects/my-app/src — admire your work
BlueBox Terminal