Lesson 2 of 16 · about 13 min
Files and folders
Create, copy, move, rename and delete files and folders by typing. Plus how to read file permissions, the rules for who can read, change or run each file.
🧭 What you need first: The shell
Your desktop is a mess: photos from three trips mixed together, a “final_FINAL_v2.docx”, and a hundred screenshots. With a mouse you’d drag files one by one into new folders.
In the shell you do it with a few short commands: make a folder, move everything that matches into it, rename what’s badly named, delete what you don’t need. And once you know the commands, you can do it for a thousand files as easily as for three.
One warning, in a friendly way: rm deletes immediately. There’s no Recycle Bin, no “are you sure?”. That’s why programmers pause for a moment before pressing Enter on an rm. (In this pretend computer, you can always press Start over.)
Another way: tidying a filing cabinet
mkdir is getting a new folder for the drawer. mv is moving papers into it (or re-labeling them). cp is making a photocopy. rm is the shredder.
Make, move and copy
Try these one at a time and watch the file map: mkdir trip, mv beach.jpg trip/, cp notes.txt notes-backup.txt, mv notes-backup.txt old-notes.txt, ls -l.
Type a command below and press Enter. Try: ls
Files
🏠 ~ (home) ← you are here
- 📄 beach.jpg
- 📄 junk.tmp
- 📄 notes.txt
The real words
mkdir, touch, cp, mv, rm:
| Command | Does | Example |
|---|---|---|
mkdir name | make a folder (-p makes missing parents too) | mkdir -p work/2026/reports |
touch file | create an empty file (or update its timestamp) | touch todo.txt |
cat file | print a file’s contents | cat todo.txt |
cp from to | copy (-r for folders) | cp notes.txt backup.txt |
mv from to | move, or rename if it stays in the same folder | mv draft.txt final.txt |
rm file | delete (-r for folders). Permanent. | rm junk.tmp |
- Wildcards match many names at once:
*.jpgmeans “every name ending in .jpg”.mv *.jpg photos/moves them all. - Permissions:
ls -lshows something like-rwxr-xr--:- The first character:
-for a file,dfor a folder. - Then three groups of three: the owner, the group, and everyone else.
r= read,w= write (change),x= execute (run it as a program, or enter it if it’s a folder). A-means “not allowed.”chmod +x script.shmakes a file runnable (lesson 4).
- The first character:
- Names with spaces need quotes:
mv "my file.txt" myfile.txt. Many programmers avoid spaces in file names for this reason.
Tidy the desktop
Make a folder called photos and move both .jpg files into it. Rename final_FINAL_v2.txt to report.txt. Delete junk.tmp.
Type a command below and press Enter. Try: ls
Files
🏠 ~ (home) ← you are here
- 📄 beach.jpg
- 📄 final_FINAL_v2.txt
- 📄 junk.tmp
- 📄 mountain.jpg
- ⬜ There is a photos folder
- ⬜ beach.jpg is inside photos
- ⬜ mountain.jpg is inside photos
- ⬜ my report
- ⬜ final_FINAL_v2.txt is gone
- ⬜ junk.tmp is deleted
Read the permissions
ls -l shows: -rwxr-x--- deploy.sh. Who can run this script?
How do you rename notes.txt to ideas.txt in the shell?
Got it?
Finish the lesson to color it in on your map and collect its concept cards.
Did this lesson click?