A beginner's guide to the MacOS Terminal [#37]
Detailed explanations of useful commands and what they do.
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
- You can access Terminal through Finder > Applications > Utilities, but I prefer to use Spotlight Search (CMD + space).
- 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.
Navigating Folders
- Your terminal should look something like this:
- 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.)
- 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.
- 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.
- Now type "ls" and press enter. You should see output that looks similar to this:
- "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.
- 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")!
- Three ways you can use "cd":
- "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.
- "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.
- "cd ~" always returns you to your home directory, regardless of what directory you're in. The swirly symbol (tilde) means "home".
Intermediate Commands
- Use "touch" to create a new file; ie. "touch mario.txt" creates a mario.txt file within the current directory.
- 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.
- Use "mkdir" (short for "make directory") to create a new directory inside your current directory; ie. "mkdir cutedogs" will create a cutedogs directory.
- 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.
- Use "networkquality" as a convenient internet speed test (or to check if your wifi has gone out).
- 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.