Lesson 2 · Unit 01
Make, move, remove
mkdir, cp, mv, rm, and how the shell expands * before a command runs
What you practise
mkdir -p,touch,cp -r,mv,rm -r, globs (*,?,[]) expand before the command runs, quoting names with spaces, whyrmhas no undo
Try a question from this lesson
Pick one
The folder is empty: there is no a yet. What does ls print after this?
mkdir a/b/c
lsCorrect answer
Nothing: mkdir refused
Why
mkdir only creates the final part of the path. Its parent a/b does not exist, so it gives up with an error and creates nothing. mkdir -p creates the missing parents too.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Copy, move, delete
cp copies, mv moves, rm deletes. Renaming is just moving to a new name.
Folders need -r (recursive) for cp and rm, because the command has to walk everything inside.
rm does not use a trash. What it deletes is gone.
cp a.txt b.txt # copy a file
cp -r src backup # copy a folder
mv b.txt c.txt # rename
rm c.txt # delete a file
rm -r backup # delete a folderConcept
Globs
A glob is a pattern the shell swaps for matching file names before the command runs. The command never sees the pattern.
* matches any run of characters, ? exactly one character, and [ab] one character from the set.
If nothing matches, the pattern is passed along unchanged.
ls *.txt # ends in .txt
ls photo?.jpg # photo1, not photo10
ls [ab]*.log # starts with a or b10 more exercises in the app
- 2× fill the blanks
- 3× type the answer
- 1× true or false
- 3× multiple choice
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.