mkdir makes a folder, cp copies, mv moves or renames, rm deletes and echo … > saves text into a file. rm is for good: there is no recycle bin in a shell, so look before you delete.
On your laptop, deleted files go to the bin. In a shell, rm means gone. Ready?
So far you've only looked. These commands change things: they make, copy, move and delete files and folders.
Predict: Read the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Try: Try it on the board and compare the result with your prediction.
Investigate: Work out why it happens, one step at a time.
Modify: Change the problem on purpose and see what happens.
Practise: A few on your own, to check you have it.
Make: Make your own problem using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
After rm
TryTry it on the board and compare the result with your prediction.
Try: back it up, then delete
Was your prediction right? Try ls: no notes.txt, and no bin to fetch it from.
Try it yourselfYour edits are saved in this browser.
Make a folder called old, copy notes.txt into it, then delete the notes.txt in your home folder.
Use the board. This ticks when you get there.
InvestigateWork out why it happens, one step at a time.
Worked example: cp or mv?
Worked exampleBefore each step, say what you think comes next.
mkdir oldMake a new, empty folder called old.
cp notes.txt oldCopy: notes.txt stays, and old/notes.txt is a second copy.
mv notes.txt oldMove: notes.txt leaves here and goes into old. Also renames: mv a.txt b.txt.
rm notes.txtDelete, for good. rm -r deletes a folder and everything in it.
echo hi > hello.txtSave some text into a file (> replaces it; >> adds to the end).
Now compare cp and mv.
Sam deletes a file. Click the line where it first goes wrong.
ModifyChange the problem on purpose and see what happens.
Vary: one change each
Try it yourselfYour edits are saved in this browser.
Rename notes.txt to todo.txt.
Use the board. This ticks when you get there.
Make a file called hello.txt that says hello, using echo and >.
Use the board. This ticks when you get there.
Delete the photos folder and both photos in it, with one command.
Use the board. This ticks when you get there.
PractiseA few on your own, to check you have it.
Safely
MakeMake your own problem using what you have learned. Expect a few tries; that is normal.
Tidy up
Then: which of today's commands would you be most careful with, and why?
Try it yourselfYour edits are saved in this browser.
Need a hint?
The result: a folder called pictures inside projects, with both photos in it, and no photos folder.
Another hint
mkdir projects/pictures, then move the photos.
Another hint
mv photos/beach.jpg projects/pictures, the same for dog.jpg, then rm -r photos.
Tidy up: both photos should end up in a new folder called pictures inside projects, and the old photos folder should be gone.
Use the board. This ticks when you get there.
For teachers
Students make folders, copy, move, rename and delete files (rm and rm -r) and save text with echo and >, learning that rm has no recycle bin (AC9TDI10K01 node 1). About 40 minutes.
I can make folders and copy, move and rename files.
I can delete files and folders, knowing it is for good.
I can save text into a file.
Before class
Try the boards yourself.
The one idea: these commands change the filesystem, and rm is permanent. Real servers have no bin; backups are how people recover.
The pretend mv and cp take one file and one destination.
Running the lesson
Predict: students who said the bin will meet the empty ls in the Try.
Worked example: ask how many copies exist after cp, and after mv.
Vary: ask why rm refuses a folder without -r.
Make: compare routes: three commands or one?
The hard part (on purpose)
The Make has more than one route; students who try one big mv and get pictures/photos inside should look at the tree and fix it, not start again.
When students get stuck
A student expects to undo rm (Sam's mistake). Ask: Where would the file have gone? Is there a bin folder? Fix: rm is final; copy first.
A student's > emptied a file. Ask: What's the difference between > and >>? Fix: > replaces; >> adds to the end.
Stretch and support
Stretch: Make a folder called backups and copy every .txt file in your home folder into it, one cp at a time. How would a script do it?
Support: Add to the card: mkdir, cp a b, mv a b, rm a, rm -r folder, echo text > file.
Where it leads
Next: Pipes.
What each step is for
after rm: Committing to where a deleted file goes tests the new move: rm deletes for good.
Try: back it up, then delete: Making a backup before deleting settles the prediction and uses mkdir, cp and rm in a safe order.
Worked example: cp or mv?: Comparing cp and mv on the same file models the new move: copy keeps the original, move doesn't. Sam expects a recycle bin, the misconception planted after the method.
Vary: one change each: Each task changes one thing: renaming with mv, making a file with echo and >, then removing a whole folder with rm -r.
safely: Choosing the safe command is the same move in mixed forms, plus a review of hidden files.
tidy up: Reorganising folders to match a description reverses the process: from the tidy result wanted to the commands that make it.