Throughout this book, you will be instructed to use the command line or terminal. Many of the tools you will be using run exclusively as command-line programs.
To access the command line on a Mac, open Finder and go to the Applications folder, then the Utilities folder. Find and open the program named Terminal (Figure 1.15).
You should see a window that looks like Figure 1.16.
To access the command line on Windows, go to the Start menu and search for “cmd.” Find and open the program named Command Prompt (Figure 1.17).
Click it to run the standard Windows command-line interface, which looks like Figure 1.18.
From now on, we will refer to “the terminal” or “the command line” to mean both the Mac Terminal and the Windows Command Prompt. If you are unfamiliar with using the command line, here is a short walkthrough of some common tasks. All commands are entered by typing at the prompt and pressing the Return key.
The command line is location based.
That means that at any given time it is “in” a particular directory within the file structure,
and any commands you enter will be applied within that directory.
The command-line prompt shows an abbreviated version of the directory it is in.
To see the whole path on a Mac, enter the command pwd
(which stands for “print working directory”), as in Figure 1.19.
On Windows, use the command echo %cd%
to see the path, as in Figure 1.20.
The directory structure of front-end projects is important.
Your projects can grow quickly, and it is best to
keep them organized from the beginning.
You will create new directories regularly during your development.
This is done using the mkdir
or “make directory” command followed by the name of the new directory.
To see this command in action, set up a directory for the projects you will build as you work through this book. Enter this command:
mkdir front-end-dev-book
Next, create a new directory for your first project, Ottergram, which you will begin in the next chapter. You want this new directory to be a subdirectory of the front-end-dev-book directory you just created. You can do this from your home directory by prefacing the new directory name with the name of the projects directory and, on a Mac, a slash:
mkdir front-end-dev-book/ottergram
On Windows, you use the backslash instead:
mkdir front-end-dev-bookottergram
To move around the file structure, you use the command cd
, or “change directory,”
followed by the path of the directory you want to move into.
You do not always need to use the complete directory path in your cd
command.
For example, to move down into any subdirectory of the directory you are in, you simply use the name of the subdirectory.
So when you are in the front-end-dev-book directory,
the path of the ottergram folder is just ottergram.
Move into your new project directory:
cd front-end-dev-book
Now, you can move into the ottergram directory:
cd ottergram
To move up to the parent directory, use the command cd ..
(that is, cd
followed by a space and two periods).
The pair of periods represents the path of the parent directory.
cd ..
Remember that you can check your current directory by using the pwd
command (or echo %cd%
on Windows).
Figure 1.21 shows the author creating directories, moving between them, and checking the current directory.
You are not limited to moving up or down one directory at a time. Let’s say that you had a more complex directory structure, like the one shown in Figure 1.22.
Suppose you are in the ottergram directory and you want to go directly
to the stylesheets directory inside of coffeerun.
You would do this with cd
followed by a path that means “the stylesheets directory inside the coffeerun directory inside the parent directory of where I am now”:
cd ../coffeerun/stylesheets
On Windows, you would use the same command but with backslashes:
cd ..coffeerunstylesheets
You may need to see a list of files in your current directory.
On a Mac, you use the ls
command for that (Figure 1.23).
If you want to list the files in another directory,
you can supply a path:
ls ls ottergram
By default, ls
will not print anything
if a directory is empty.
On Windows, the command is dir
(Figure 1.24), which you can optionally give a path:
dir dir ottergram
By default, the dir
command will print information
about dates, times, and file sizes.
On some versions of OS X and Windows, you will need superuser or administrator privileges in order to run some commands, such as commands that install software or make changes to protected files.
On a Mac, you can give yourself privileges by prefixing a command with sudo
.
The first time you use sudo
on a Mac, it will give you a stern warning,
shown in Figure 1.25.
sudo
will prompt you for your password before it runs the command as the superuser.
As you type, your keystrokes will not be echoed back, so type carefully.
On Windows, if you need to give yourself privileges you do so in the process of opening the command-line interface. Find the command prompt in the Windows Start Menu, right-click it, and choose Run as Administrator (Figure 1.26). Any commands you run in this command prompt will be run as the superuser, so be careful.
52.15.135.175