Executing a Series of Commands

Learn how to execute a series of commands.

One common pattern we’ll find yourselves doing repeatedly is creating a directory and then switching to the directory we just created, like this:

$ mkdir workstuff
$ cd workstuff

The && operator

We can execute multiple commands at once by placing two ampersands (&&) or a semicolon between the commands. These methods work differently, so let’s explore both.

Using two ampersands requires that the first command completes successfully. Let’s try to create the directory /tmp/websites/awesomeco using the mkdir command, but we omit the -p switch so it won’t attempt to create parent folders that don’t exist. Then we use two ampersands, followed by the cd command to switch to the new directory:

$ mkdir /tmp/websites/awesomeco && cd /tmp/websites/awesomeco

Use the terminal below to practice these commands.

Get hands-on with 1200+ tech skills courses.