The Terminal
Before you write a line of HTML, you need to get comfortable in the terminal. Almost everything in this series runs through it. The sooner it feels normal, the better.
Open Terminal. On macOS it’s in /Applications/Utilities/. On most Linux distributions you can get to it with Ctrl+Alt+T, or find it in your application launcher. When it opens, you’re sitting in your home directory. That’s the starting point for everything.
Who are you and where are you
Two commands to start. Neither one does anything to your filesystem. They just tell you things.
whoamiThis prints your username. On a machine named after your dog, on a shared work server, on a VPS you just spun up, whoami tells you who the system thinks you are. It’s a small command, but it matters when you’re working in environments where user permissions and file ownership are relevant (and in web development, they often are).
lsls lists the contents of your current directory. Run it now and you’ll see the familiar top-level folders from your $HOME: Desktop, Documents, Downloads, and so on. This is your home directory.
Make a project folder
You’re going to create a folder for the project you’ll be building throughout this series. A common convention is to keep all your development projects in a folder called dev or projects in your home directory. That’s what we’ll do here.
mkdir tutorialsmkdir stands for “make directory.” You’ve just created a folder called tutorials in your home directory. Run ls again and you’ll see it.
Now move into it:
cd tutorialscd stands for “change directory.” You’re now inside tutorials. If you run ls here, you’ll get nothing back. The folder is empty.
Build out some structure
Let’s add a few subdirectories to work with:
mkdir src
mkdir dist
mkdir docs
mkdir notesYou can also do this in one line:
mkdir src dist docs notesRun ls again. All four folders are there.
Remove what you don’t need
You don’t actually need notes for this project. Let’s remove it.
rm -r notesThe -r flag stands for “recursive.” On its own, rm removes files. To remove a directory and everything inside it, you need -r. Since notes is empty, it would also work with rmdir notes, but rm -r notes is the habit worth building because directories are rarely empty in practice.
Run ls one more time. Three folders: src, dist, docs.
A word of caution: rm is permanent. There’s no trash, no undo, no recovery prompt. What you delete is gone. Get used to pausing for a half-second before you run it.
Move around
You’re currently inside ~/tutorials/ directory from previously changing directories into it. Here’s how to change directories out of it.
To go up one level, to your home (~) directory:
cd ..In the command above .. (two periods) is shorthand for “parent directory of” and we can remember what cd means from above. Put it all together and the command becomes a statement:
change directories [parent directory of]
Now you’re back in your home, run ls here and you’ll see tutorials in the list alongside your other home directory folders.
To change directories back down into tutorials:
# change directories tutorials or
cd tutorialsOr from home, to go directly into a subdirectory:
cd tutorials/srcTo go up two levels at once:
Likewise, after going down two levels go back up two levels:
cd ../..That command should read to you as “change directory: parent directory of, parent directory of”. With that statement in mind, you might notice a pattern emerging:
cdis a COMMAND which takes an ARGUMENTCOMMAND [ARGUMENT]- Together they make a statement which can be acted on
cdCOMMAND takes ARGUMENTS which has the effect of changing the current working directory- one may
cdup the file tree one directory..or multiple directories../../../at a time - one may also
cddown the tile tree one directorychild/or multiple directorieschild/grand-child/great-grand-child/at a time - one space seperates the command from the argument
cd is just one example of the common COMMAND [ARGUMENT] pattern which you’ll be seeing plenty more of.
Each .. is one level up. Chain them with / to climb multiple levels in a single command.
One more useful shortcut: no matter where you are in the filesystem, this takes you straight home:
cd ~~ is shorthand for your home directory. You’ll see it used often.
What you now know
You can orient yourself in the filesystem (whoami, ls), create folders (mkdir), move into and out of them (cd), and delete what you don’t need (rm -r). That’s enough to work with. In Chapter 2, you’ll initialize a Git repository inside the tutorials folder and start tracking your work.