Creating Files and Folders
Introduction
So far, every command you've run has looked at something that already existed. ls showed you what was inside a folder, and cd walked you into folders someone else had already made. In this lesson, that changes: you'll start bringing new folders and files into existence yourself, exactly where you name them. The two commands driving this are mkdir, which makes a new directory, and touch, which makes a new empty file.
Along the way, you'll pick up naming habits that keep your files easy to find and free of surprises. And you'll build a habit worth keeping for the rest of this course: checking with ls right after you create something, so you know for certain it landed where you meant.
Making Folders with mkdir
mkdir is short for "make directory." You provide it with a name, and it creates a new folder with that name at the location you specify. It's the simplest way to shape the filesystem instead of just observing it — every folder you've navigated into over the last two lessons had to be created by someone, at some point, with a command just like this one. Both mkdir and touch are standard command-line utilities included with macOS, so there's nothing to install on your Mac, and on CodeSignal, they're already available.
Let's set up a workspace to practice in, right alongside the travel project from Lesson 3.
That error is expected. Projects already exists from Lesson 3's setup, and plain mkdir refuses to create something that's already there. Hold onto this moment — it's exactly the problem the -p flag solves in the next section. For now, let's step around it by moving into the folder that does exist and creating something fresh underneath it.
cd Projects moved into the folder that already existed. mkdir create made a brand-new folder for this lesson's practice — safe, since create didn't exist yet. cd create stepped inside it, and mkdir project created a single folder right where you were standing. ls confirms it: project is the only thing inside create.
Building Nested Chains with mkdir -p
Right now, project is just one empty folder. Suppose you want to add an assets folder inside it, and inside that, an images folder — two levels deep in a single command. Plain mkdir can't do this: it expects every folder except the very last one in the path to already exist, and it stops the moment it hits one that's missing.
The error tells you exactly why: assets doesn't exist yet, so mkdir has nowhere to put images. This is the same kind of problem you ran into with Projects a moment ago, just one level deeper.
The fix is the -p flag, short for "parents." It tells mkdir to create every missing folder along the path, not just the last one. Give it a path several folders deep, and if none of those folders exist yet, mkdir -p creates all of them in a single command.
mkdir -p built the entire chain — assets and images — in one line, even though neither existed a moment ago. The first ls confirms assets now lives inside project, and the second confirms images lives inside assets.
There's one more piece worth adding: -v, short for "verbose." On its own, mkdir works silently — no news is good news. -v changes that by printing a line for every folder it actually creates, so you can read the outcome directly instead of running ls to infer it.
Two lines came back because two folders were missing: notes and monday. Each got its own line the moment mkdir created it. Combined with -p, -v turns a silent operation into one that reports its work as it happens.
Now here's the property that matters most for every script you'll ever write with mkdir -p: it doesn't treat a directory that already exists as an error.
Compare this to the very first error you saw in this lesson, when plain mkdir refused to remake Projects. mkdir -p has no such objection: it skips the directories that are already there and builds only the ones that are missing. That's what makes it safely repeatable inside a setup script — as long as the path is a valid, accessible chain of directories. It can still fail for other reasons: a folder you don't have permission to write into, a read-only disk, or a path component that turns out to be a file rather than a directory.
