Terminal Commands: The Ultimate Manual

As a developer, you should always be looking for tips and shortcuts to make your life easier. You can program more efficiently when you understand the terminal and command line.

This guide will explain everything you need to know about terminal commands, including what they are, how they work, examples, and how to get started.

What are Terminal Commands Anyway?

Terminals, also known as consoles or command lines, make it possible for developers to automate tasks and execute commands without a graphical user interface (GUI).

With a terminal, you can send a simple text command to your computer for basic computer tasks or advanced programming functions.

GUIs have definitely simplified many tasks for development and programming. But terminal commands are more flexible and efficient for getting certain jobs done. When used correctly, terminal commands can eliminate tedious labor, pointing, and clicking that’s required within a GUI.

How Terminal Commands Work

Terminal commands work best when applied to basic and repetitive tasks. When chained together, they allow users to increase output and work faster.

Instead of moving your mouse to an area of your computer, opening a file, scrolling, and clicking on something manually, you can use terminal commands to perform this action automatically.

Now imagine this repetitive process at scale. Even for something basic like navigating to a folder, opening a file, and copying a document—it could take you hours if you’re doing it thousands of times.

Terminal commands let you manipulate the computer to execute a task, as opposed to manually doing it yourself.

There are two main ways to use terminal commands. You can interactively leverage the command-line environment by entering a command and waiting for the result or you can compose scripts in the shell that run without your direct input.

The first option is better for simple or one-off tasks, and the latter is ideal for automating a long list of repetitive actions at scale.

To truly understand how terminal commands work at a higher level, we’ll take a look at some real examples that you can replicate and follow. Some of these examples are extremely basic, and others are a bit more advanced.

Example #1: cd

The cd command stands for “change directory.” This means that we’re going to switch the folder that we’re currently in.

When using this terminal command, we can add more text to tell the computer where to move:

  • cd.. — Moves back a level to the parent folder.
  • cd../.. — Moves back two levels (continue adding /.. for each level you want to move)
  • cd ~ — Moves to the home directory.
  • cd — Moves to the name of the folder entered.

Pro tip: If you’re typing a file name or folder name and it’s only a single level ahead, just click “Tab” on your keyboard. The terminal will automatically fill in the file or folder name.

Example #2: pwd

The pwd command stands for “print working directory.” As the name implies, this terminal command will show you the exact file path or folder path for your existing location.

This command can be really useful if you get lost, lose your place, or can’t figure out which directory you’re in. Typing pwd into the terminal will show your current path, so you can get back on track.

Example #3: clear

The clear command is as straightforward as it gets. Enter this into your terminal, and it clears everything out.

This command is ideal for times when you just want to work with a clean slate. If you’ve been entering a ton of different commands and it’s starting to clutter your terminal, just run enter clear to eliminate everything from the screen.

It’s also worth noting that you can press Command+K on your keyboard to execute the same action, rather than typing clear into the terminal.

Example #4: ls

Once you’re in a folder, you can quickly see everything that’s in that folder with the ls command.

If you want to see all files in the folder, including those that are hidden, run type in ls -a.

Want to see even more information about each file? Type ls -l into the terminal. This will show you the owner, date created, permissions, and more.

Example #5: mkdir

The mkdir command stands for “make directory.” In simple terms, this terminal command tells the computer to make a new folder.

Any time you run a mkdir command, the terminal will automatically create a new folder in that place. To add a new folder in a specific location, just use the cd command that we explained previously.

That will put you into your desired location for the new folder, and then you can just enter mkdir into the terminal.

If you want to get into this new folder, type cd after it’s been created.

Example #6: rmdir

Now that you know how to make a directory, you can remove one with the rmdir command. This stands for “remove empty directory.”

Let’s say you just created a new folder, but it has the wrong name. Enter rmdir followed by the path to remove it completely.

Alternatively, you could just use an mv terminal command to rename it.

Example #7: rm -R

The rm -R command removes nested directories. This is used for situations when you want to remove a folder that contains additional folders and files.

There’s a difference between using the rm -R command compared to just deleting a file manually. If you delete a file from your finder window, you can always just restore it from your trash. But the rm -R terminal command deletes it permanently.

So make sure you use this cautiously.

Once executed, it will immediately delta all of the files and folders in the path you specified in the command. There’s no turning back.

Example #8: sudo

sudo commands change your user privileges to an administrator. It stands for “superuser do.”

In short, these elevated privileges are required to run certain commands. For example, let’s say you want to delete a file that was created by another user. You’d likely need to run a sudo command to make this work.

Any time you run a sudo command, the terminal prompts you to enter a password. Once you enter the password, you’ll be able to execute the desired command.

Example #9: top

The top command shows all of the system stats directly in your terminal window. You can see stats related to CPU, memory, disk utilization, and all of the apps that are currently running.

Along with the apps, you’ll see the app CPU usage, ports used, the state of the apps, memory per app, and other information.

This is essentially all of the stats you’d get if you opened your activity monitor. But rather than wasting valuable time and navigating to another app, you can simply execute the top command to see everything immediately.

Example #10: ditto

As the name implies, the ditto command is a fast and easy way to copy the contents of one folder to another. This is a commonly used terminal command if you’re starting a new project but want to use an old project as a template or base.

It’s also used if you want to copy folders or files from your device to an external hard drive.

If you want to see a verbose output of each file you’re copying, add -V to your command line, so it looks like this: ditto -V FolderOne NewFolderOne.

How to Get Started With Terminal Commands

Now that you understand how terminal commands work, it’s time to start running terminal commands on your own. Like anything else, it’s easier if you start with the basics before moving to more advanced terminal commands.

The steps below will get you started in the right direction.

Step 1: Access the Terminal

Any Mac that was built after Mac OS X launched back in 2001 has the terminal app on the computer. Navigate to Applications, then click on Utilities. The Terminal application will be in there.

Alternatively, you can search for the application by opening a new finder window and navigating to the search bar.

When you open the terminal for the first time, you should see a command prompt ending with a $ sign in the following format:

ComputerName:CurrentDirectory Username$

You can start to enter commands directly after this existing command prompt. Remember, you can’t add source code to the terminal. You’re simply using this function to execute different tasks on the computer.

Windows users will have “cmd” built into the system. But you’ll need to download Microsoft PowerShell to run certain commands. So it’s in your best interest to install that before you proceed.

Linux users won’t need to download anything to execute terminal commands. Depending on your system, you should be able to run these using the gnome-terminal, xterm, konsole, kvt, rxvt, eterm, or nxterm.

Step 2: Use the Command Line

Once you’re in the terminal, you can use the command line to start executing different tasks.

As you’ve seen from the examples earlier, there are lots of different options to consider. It all depends on what you’re trying to accomplish.

The command line helps you with development-related tasks, scripting, and automating actions. It’s just a faster and more flexible way to do things when you compare it to manually using the mouse and clicking through your folders.

Every command has three different parts—utility, flags, and arguments. The utility always comes first. The flags and arguments follow, depending on their rules.

Refer back to the examples we covered previously. In those examples, cd, pwd, and clear are all utilities. That’s because they explain what you want to do.

In many cases, you can run a utility alone without a flag or argument. But most people using the command line want to get more out of the utilities, so they add flags and arguments.

A flag changes how your utility operates. Rather than using a default, the flag essentially modifies how the command works.

We saw this earlier when we took the ls command and changed it to ls -a. The -a flag tells the computer to show all files in the folder.

An argument takes that one step further. As we explained with the cd command, you can enter a as well, which would be considered the argument. This tells the command line which directory we want to move to.

Once you’ve typed your commands, just press enter on your keyboard to execute them.

Step 3: Practice

Learning how to use terminal commands might seem a bit intimidating or overwhelming when you’re first getting started. But don’t get discouraged if you’re a beginner.

My best advice for you is to keep practicing.

At first, using terminal commands might actually take you longer to perform a specific task than if you were to do it with your mouse. But that’s just because it feels foreign to you right now. The more you practice, the faster it will come to you.

Then you’ll quickly see how much more efficient it is to use the terminal commands than your mouse. Just ask any experienced developer or programmer—they’re all using terminal commands.

One of the hardest parts is memorizing commands. Again, this comes naturally the more you do it.

Think of it like a keyboard shortcut or function that you’ve used forever. If you want to copy something on a Mac, you can just click command+C on your keyboard. To paste it, click command+V. On a PC, the control key allows these same shortcuts.

You don’t have to look up these shortcuts. They’re embedded into your brain because you’ve been using them for years, and you’ve realized it’s faster than right-clicking, and navigating to copy or paste with the mouse.

The same analogy can be applied to terminal commands. Your brain will eventually memorize the commands the more you use them, and you’ll start to fly through the commands without thinking twice about anything.

If you’re not sure what to practice, just continue running through the examples listed in this guide. That’s the best place to start before you move on to more advanced terminal commands.

Every company that uses Google Workspace should be using Nira.
Bryan Wise
Bryan Wise,
CIO of GitLab

Incredible companies use Nira