PLAINFINCH learn by building

Making files and folders

You will make new folders, including several levels at once, and create empty files to fill in later.

How do you make a folder?

Type mkdir followed by the name you want. mkdir photos makes a folder called photos inside the folder you’re in. The name stands for make directory, and directory is the older word for folder. When it works, it prints nothing at all. The prompt comes back, and ls now shows photos/ in the list.

You can make several folders at once by listing them: mkdir photos invoices drafts makes three folders side by side. That’s handy, and it also explains a common accident. If you type mkdir staff rota hoping for one folder called “staff rota”, you get two folders, staff and rota, because the shell splits words at spaces before mkdir ever sees them.

If the name is already taken, mkdir refuses and leaves the existing folder alone. Run mkdir photos twice and the second time prints mkdir: cannot create directory 'photos': File exists. Nothing inside the old folder is touched, so this error is harmless.

mkdir photos
mkdir photos invoices drafts
ls

Why does mkdir say No such file or directory?

Plain mkdir only makes the last folder in a path. If you ask for orders/2026/march and orders doesn’t exist yet, it has nowhere to put 2026, and it stops with an error. In this practice terminal the line reads mkdir: cannot create directory 'orders/2026': No such file or directory when you try a two-level path, and a real bash on Linux prints the same words.

The message is confusing at first, because you were trying to create something, so of course it doesn’t exist. Read it as “a folder on the way to this one is missing”. The fix is either to make each level in turn, or to add -p.

What does mkdir -p do?

The -p option tells mkdir to make every missing parent folder along the path. mkdir -p orders/2026/march makes orders, then 2026 inside it, then march inside that, in one command. The p stands for parents.

It has a second effect that people rely on in scripts: with -p, a folder that already exists is not an error. Running mkdir -p photos when photos is there prints nothing and changes nothing. That makes it safe to put at the top of a script that might run many times, such as one that files each day’s orders into a dated folder.

Add -v if you want to see what was made. mkdir -pv orders/2026/april prints one line for each folder it creates. On a real Linux system that gives you a line for every new level; this practice terminal prints one line per name you typed, which is enough to confirm it worked.

mkdir -p orders/2026/march
ls -R orders

How do you make an empty file?

Use touch. touch saturday.txt makes an empty file called saturday.txt if there isn’t one. You can name several files at once, or give a path: touch orders/2026/march/saturday.txt works as long as the march folder exists. If it doesn’t, touch fails with “No such file or directory”, the same way plain mkdir does, because touch never makes folders.

If the file already exists, touch doesn’t empty it or change a single letter inside. It only updates the file’s modified time to now. That’s where the name comes from: you touch the file so it looks freshly changed. You can see the time move in ls -l.

Empty files are more useful than they sound. A placeholder such as README.txt reminds the next person what belongs in a folder, and some programs look for a marker file to decide what to do. Most of the time, though, you’ll make a file by opening it in an editor.

touch README.txt
touch orders/2026/march/saturday.txt
ls -l README.txt
FigureThe bakery folder before and after three commands. After mkdir -p, touch and mkdir photos it holds orders/2026/march with an empty saturday.txt inside, plus a new photos folder.The bakery folder before and after three commands. After mkdir -p, touch and mkdir photos it holds orders/2026/march with an empty saturday.txt inside, plus a new photos folder.
One mkdir -p made three folders, one inside the next, and touch put an empty file at the bottom. The existing files were left exactly as they were.

What does nano do?

nano is a small text editor that runs inside the terminal. nano notes.txt opens the file for editing, and if the file doesn’t exist yet, it starts a new one with that name. In a real terminal, nano fills the window, you type, then press Ctrl+O and Enter to save and Ctrl+X to leave. The keys are listed along the bottom of its screen, where ^ means Ctrl.

In this practice terminal, nano, vi and code all open the file in an editor tab above the terminal instead, and your changes save as you type. The file appears in the Files view straight away. On a real computer, nano only creates the file when you save, so quitting without saving leaves nothing behind.

On a Mac, typing nano works too; recent versions run pico, a near twin, under that name. Many servers also have vi or vim, which works very differently and is famous for being hard to quit: press Esc, type :q! and press Enter to leave without saving. When a tutorial tells you to edit a file on a server, nano is the gentler choice if it’s there.

What makes a good file name?

Use lowercase letters, numbers and hyphens, and keep spaces out. wholesale-orders.csv is easy to type, never needs quotes and works the same on every system. Wholesale Orders (final).csv needs quotes every time you use it, and the capital letters can break links on a Linux web server, where Menu.csv and menu.csv are different files.

Put dates in year, month, day order: 2026-03-14-orders.csv. Files named that way sort into date order with plain ls, which is a small thing you’ll be glad of in a folder with two hundred of them. The same idea works for folders, which is why the task builds orders/2026/march.

Avoid starting a name with a hyphen, since commands read anything starting with - as an option. Avoid characters the shell treats specially, such as *, ?, $, & and quotes. A dot at the start makes a hidden file, like .bashrc, which plain ls doesn’t show. That’s useful for settings files and confusing for anything else.

How do you check what you made?

Silence after mkdir or touch means it worked, but it’s good practice to look. ls shows the new names in the current folder. ls -R orders lists orders and every folder inside it, level by level. In this practice terminal the end of the task looks like this:

ls -l adds detail. Folders start with a d in the first column and files with -, and an empty file made by touch shows a size of 0. The Files view on the right shows the same thing as a tree, with a badge on each new item.

$ ls -R orders
orders:
2026/

orders/2026:
march/

orders/2026/march:
saturday.txt

What do AI tools get wrong here?

AI assistants often write mkdir without -p for a nested path, then follow it with commands that assume every level exists. If the first line fails, everything after it fails too. When a suggestion makes folders, check for -p or make the levels yourself.

They also invent names with spaces and capitals, copied from how a person described the folder: mkdir "Wholesale Orders". It works, but every later command needs the quotes, and some tools handle them badly. Rename it to wholesale-orders before you start. Finally, some answers use Windows commands such as md or type nul > file.txt. In bash, use mkdir and touch.

Field notes

  • mkdir name makes one folder inside the folder you are in.
  • Plain mkdir fails if a parent folder in the path is missing.
  • mkdir -p makes every missing folder along the path in one go.
  • touch makes an empty file, or updates the date on one that exists.

Easy to get wrong

Without -p, mkdir only makes the last folder and fails when orders or 2026 is missing. With -p it makes every level and doesn’t complain if some already exist.

The space splits the name into two arguments, so you get two folders. Use a hyphen, or quotes if you really need the space.

touch makes files, never folders. Make the folder path first.

Questions people ask

Does touch empty a file that already has text in it?

No. On an existing file, touch only updates its modified time. The contents stay exactly as they were. To empty a file you’d use redirection, which a later lesson covers.

Can I make a file and a folder with the same name?

Not in the same folder. photos can be a file or a folder, never both. If touch photos made a file first, mkdir photos fails with “File exists”.

Is mkdir the same on a Mac?

Yes. mkdir, mkdir -p and touch work the same in the Mac Terminal with zsh. The -v output is worded slightly differently on a Mac, which doesn’t change what gets made.

Why is my new file not showing in ls?

Check where you are with pwd. The file was made in the folder you were in when you ran the command, or at the path you gave. If its name starts with a dot, use ls -a.

Keep going