Unit 2: Making Things
Folders, files, copies and the delete key.
Unit 2 of 8 in Linux and the command line for kids. Its 7 lessons are New Folders, New Files, Reading a File, Copying, Moving and Renaming, Deleting and Tidy the Desktop — below is everything each one explains, and a question or two from it to try.
Every terminal session on this page was replayed before it shipped, on a machine whose every message is tested against real bash and coreutils.
This unit is free for ever, because the first two units of every track are. Try it in the app.
📁 New Folders
Make a directory
Linux calls a folder a directory. Same thing, older word.
mkdir makes one. Give it a name and it appears — no window, no dialog box, no "are you sure".
Terminal
kid@alguni:~$ mkdir photos kid@alguni:~$ ls photos
Several at once
Give mkdir more than one name and it makes them all. Most commands work like that: whatever you can do to one file, you can usually do to twenty.
That is the whole reason a terminal is worth learning.
Terminal
kid@alguni:~$ mkdir maths english art kid@alguni:~$ ls art english maths
When the way there does not exist yet
Ask for school/maths/homework when there is no school yet and mkdir stops: it will make one folder, not three.
-p means "make the parents too". It is the difference between a complaint and a whole path appearing at once.
Terminal
kid@alguni:~$ mkdir school/maths/homework mkdir: cannot create directory 'school/maths/homework': No such file or directory kid@alguni:~$ mkdir -p school/maths/homework kid@alguni:~$ ls school maths kid@alguni:~$ ls school/maths homework
Try it yourself
What does -p do for mkdir?
- Makes every folder on the way there as well
- Prints the folder it made
- Protects the folder from deleting
- Puts the folder in your home
Answer it in the app
📄 New Files
An empty one
touch makes an empty file. Nothing in it at all — just a name on the disk, waiting.
It is useful more often than it sounds, because plenty of programs only need the file to *be there*.
Terminal
kid@alguni:~$ touch diary.txt kid@alguni:~$ ls diary.txt
With something in it
echo says something back to you. On its own it is not very useful.
But > catches what a command was about to print and puts it in a file instead. That arrow is one of the best ideas in the whole system, and unit 4 is entirely about it.
Terminal
kid@alguni:~$ echo "hello there" hello there kid@alguni:~$ echo "hello there" > greeting.txt kid@alguni:~$ cat greeting.txt hello there
Adding instead of replacing
That is the trap: > throws away whatever was in the file.
>> adds to the end instead. One arrow replaces, two arrows add on. It is worth saying out loud a few times.
Terminal
kid@alguni:~$ echo "monday" > week.txt kid@alguni:~$ echo "tuesday" >> week.txt kid@alguni:~$ echo "wednesday" >> week.txt kid@alguni:~$ cat week.txt monday tuesday wednesday
Try it yourself
What does the last line print?
Terminal
echo "one" > count.txt
echo "two" > count.txt
cat count.txt
Answer it in the app
🔎 Reading a File
Concatenate
cat prints a file. Its odd name is short for concatenate, because it can print several files stuck together one after another.
That is what it was really built for. Printing one file is just the thing everybody uses it for.
Terminal
kid@alguni:~$ cat monday.txt sausages kid@alguni:~$ cat monday.txt tuesday.txt sausages pasta
Just the beginning, just the end
Some files are enormous. cat on a file with a million lines is not helpful.
head shows the first ten lines, tail shows the last ten, and -n says how many you actually want.
Terminal
kid@alguni:~$ head -n 3 numbers.txt 1 2 3 kid@alguni:~$ tail -n 3 numbers.txt 98 99 100
When the file is not there
Ask for a file that does not exist and cat says so, using the name you gave it.
Nine times out of ten that message means you are standing somewhere else than you thought. pwd and ls are the fix.
Terminal
kid@alguni:~$ cat homework.txt cat: homework.txt: No such file or directory
Try it yourself
What does this print?
Terminal
head -n 2 letters.txt
Answer it in the app
📑 Copying
From, then to
cp copies. It always takes two things: what to copy, then where to put it.
That order never changes, in cp or in mv. From first, to last.
Terminal
kid@alguni:~$ cp story.txt backup.txt kid@alguni:~$ ls backup.txt story.txt kid@alguni:~$ cat backup.txt chapter one
Into a folder
If the last thing you name is a folder, the copy goes inside it and keeps its name.
That is how you copy several files at once: name them all, and put a folder last.
Terminal
kid@alguni:~$ cp a.txt b.txt backups kid@alguni:~$ ls backups a.txt b.txt
Copying a whole folder
Try to copy a folder and cp refuses, because copying a folder means copying everything inside it and it will not assume you meant that.
-r means recursive: go in, and keep going in. You will meet -r again on the command that deletes, where it matters a great deal more.
Terminal
kid@alguni:~$ cp project copy cp: -r not specified; omitting directory 'project' kid@alguni:~$ cp -r project copy kid@alguni:~$ ls copy/notes plan.txt
Try it yourself
What does cp -r do that plain cp will not?
- Copy a folder and everything inside it
- Rename the copy
- Copy the file twice
- Replace a file without asking
Answer it in the app
🚚 Moving and Renaming
One command for two jobs
mv moves a file into a folder. Same shape as cp: from first, to last.
The surprise is that there is no rename command — because renaming is just moving without going anywhere. Move old.txt to new.txt and you have renamed it.
Terminal
kid@alguni:~$ mv untitled.txt rocket-plan.txt kid@alguni:~$ ls plans rocket-plan.txt kid@alguni:~$ mv rocket-plan.txt plans kid@alguni:~$ ls plans kid@alguni:~$ ls plans rocket-plan.txt
Names with spaces in them
The shell splits what you type at every space, so my homework.txt looks like two things to it.
Put quotes round a name with a space in it and the shell keeps it whole. This is the first hint that the shell is a language with rules, which is where unit 7 goes.
Terminal
kid@alguni:~$ touch "my homework.txt" kid@alguni:~$ ls my homework.txt kid@alguni:~$ mv "my homework.txt" homework.txt kid@alguni:~$ ls homework.txt
Try it yourself
How do you rename cat.txt to dog.txt?
- mv cat.txt dog.txt
- rename cat.txt dog.txt
- cp cat.txt dog.txt
- mv dog.txt cat.txt
Answer it in the app
🗑️ Deleting
There is no bin
This is the one to be careful with. rm removes a file, and there is no recycle bin to get it back from. It does not ask. It just goes.
That is not the terminal being cruel. It is the terminal doing exactly what you said, which is what you want the rest of the time.
Terminal
kid@alguni:~$ ls keep.txt rubbish.txt kid@alguni:~$ rm rubbish.txt kid@alguni:~$ ls keep.txt
Empty folders
rmdir removes a folder, but only if it is empty. That refusal is a safety catch, not a nuisance: it is the computer checking you know what is in there.
Terminal
kid@alguni:~$ rmdir empty kid@alguni:~$ rmdir full rmdir: failed to remove 'full': Directory not empty kid@alguni:~$ ls full
The dangerous one
rm -r deletes a folder and everything inside it, all the way down, without asking once.
It is genuinely useful and it is how people lose a year of work. The habit that saves you is boring and it works: run ls on the folder first, and read what comes back.
Terminal
kid@alguni:~$ ls old notes.txt pictures kid@alguni:~$ rm -r old kid@alguni:~$ ls
Try it yourself
You type rm -r photos and press enter. What happens?
- photos and everything in it is gone, with no way back
- It asks you first
- It moves photos to the recycle bin
- It refuses, because photos is not empty
Answer it in the app
🏆 Tidy the Desktop
A real job
Somebody has dumped fifteen things in one folder. Photos, homework and rubbish, all mixed together.
You have everything you need: mkdir, mv, rm, and ls to check as you go.
Try it yourself
Which of these can you not undo?
- rm -r photos
- cp photos backup
- mkdir photos
- ls photos
Answer it in the app