A beginner's guide to the MacOS Terminal [#37]

Detailed explanations of useful commands and what they do.

A beginner's guide to the MacOS Terminal [#37]

NOTE: this guide is only for Mac users.

Press CMD (⌘) + space, then type "terminal" and hit enter. Boom. Now you're in Terminal. The Terminal window looks pretty hardcore, but it's the best way to issue commands directly to the computer. And if you've never used Terminal before, I'm going to show you some really cool stuff.

Terminal Basics

  1. You can access Terminal through Finder > Applications > Utilities, but I prefer to use Spotlight Search (CMD + space).
  2. To open a new tab in Terminal, you can use CMD + T. To close those tabs, you can use CMD + W. CMD + Q quits Terminal, and CMD + K clears Terminal.
  1. Your terminal should look something like this:
  1. Practically everything on your computer is either a file or a folder. You can put folders and files inside of folders, but you can't put folders or files inside of files. NOTE: A directory is basically the same thing as a folder. (I'll use "directory" and "folder" interchangeably in this guide.)
  2. When you're in Terminal, you're always in a directory. To see what directory you're currently in, type "pwd" (short for "print working directory") into Terminal and press enter.
Right now, I'm in /Users/olympus, which is my home directory.
  1. So I'm in my "olympus" directory right now, which is inside the "Users" directory. Whenever you type "pwd" and press enter, it might display something different – and that's fine! You may be in a different location than I am.
  2. Now type "ls" and press enter. You should see output that looks similar to this:
  1. "ls" (short for "list") lists the current files and folders in the directory you're currently in. So in my "olympus" directory, I have a "Desktop" folder, a "Downloads" folder, and a bunch of other folders.
  2. Now you can figure out what directory you're in (with "pwd") and list what's in that directory (with "ls"). But you're stuck in one folder. How can you change folders? You can use "cd" (short for "change directory")!
  3. Three ways you can use "cd":
    1. "cd" followed by the name of a directory moves you to that directory; ie. "cd Movies" (if you're in the home directory) would move you to the "Movies" directory.
    2. "cd .." sends you back to the previous directory; ie. if I ran "cd .." while in the "Movies" directory, I would be moved back to my home directory.
    3. "cd ~" always returns you to your home directory, regardless of what directory you're in. The swirly symbol (tilde) means "home".
The various ways you can use "cd".

Intermediate Commands

  1. Use "touch" to create a new file; ie. "touch mario.txt" creates a mario.txt file within the current directory.
  2. Use "cat" to read the contents of a file; ie. "cat hello.txt" will print the contents of hello.txt. WARNING: Don't do this with image files, as the output will look like gibberish.
  3. Use "mkdir" (short for "make directory") to create a new directory inside your current directory; ie. "mkdir cutedogs" will create a cutedogs directory.
  1. Use "man" followed by the name of a command to print documentation of that command; ie. "man cat" will print documentation about the "cat" command. Press "q" to exit a man command page.
  1. Use "networkquality" as a convenient internet speed test (or to check if your wifi has gone out).
  2. To exit a running program, use CTRL + C.

Conclusion

Terminal is really powerful! These commands might seem intimidating at first, but they get easier with practice. Plus, you can do some things with Terminal that are nearly impossible (or take way longer) to do elsewhere.