Lessons · Terminal · making a folder
Making folders
mkdir name makes a folder. mkdir -p a/b/c makes the whole chain at once and stays quiet if it already exists.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Every project starts with a few folders, and scripts that set up folders must not fail on the second run.
How to think about it
Reach for -p whenever there is a chain to make or the folder might already be there. Then ls to see it.
Worked example
mkdir -p site/css site/jsTwo folders inside a new site folder, parents made as needed.
ls sitecss and js.
mkdir -p site/cssAlready there: no error, nothing changes.
echo $?0: it counted as success.
Your turn
Make the chain build/out/logs in one go.
mkdir build/out/logs
Try it at a real prompt
The trap
mkdir a/b/c without -p when a does not exist: 'No such file or directory', because mkdir will not invent the parents on its own.
Practise making a folder on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.