Shoot Bird
Learn How to Use Terminal
Thu Nov 01, 2018 · 984 words
The Terminal
Figure 1. Scary Computer Stuff (or How I Learnt to Stop Worrying and Love the Terminal).

Overview

The terminal (and it’s Windows counterparts, the Command Prompt and PowerShell) are terrifying to behold if you have no idea what you’re doing. In When to Start Naming Things, we’ve talked about text labels and design conventions in graphic interfaces. But what do you do when you’re faced with nothing but a blinking text cursor, and nothing else? And why would you want to use such a thing in the first place?

Precision + Speed

Graphic interfaces are great at giving you precision on a slow drip. Given a list of files, you can be very precise in selecting files to delete given that you’ve had the time to:

  1. Hold down the key and click each file in turn to select them.

  2. Pressing ⌘+delete to move them to the trash.

  3. Right-clicking the 🗑 icon and selecting "Empty Trash".

Or you could just type the following in the terminal to remove all pdf files in the target-directory folder:

cd target-directory
rm *.pdf
Warning
rm completely skips moving files to the Trash. Once you do this, you cannot recover your files without using a disk forensics tool.)

Quickly Copy+Paste Stuff

Another really useful thing you can do is this: on macOS, you have a tool called pbcopy, which allows you to send text to your clipboard. I use this to quickly copy and paste snippets of text for, let’s say, emails. Here’s how it works:

  1. Open your terminal by going to Applications > Utilitites > Terminal, or by using spotlight: press ⌘+space and type terminal to find it.

  2. In the terminal, create a new directory by typing the following: mkdir tmp

  3. Press enter to run the command.

  4. Go into the tmp directory you’ve just created by running the following command: cd tmp

  5. Make a revert.txt text file by running the following command:

echo "As per my last email; please revert. Thanks." >> revert.txt
  1. To quickly see the contents of the file, run cat revert.txt [1]

  2. Copy the contents of revert.txt to your clipboard by running:

cat revert.txt | pbcopy
Tip
The pipe | is used to hand over data from one command to another. In cat revert.txt | pbcopy, the | takes the result of cat revert.txt and tells the next command, pbcopy that they have to work with it.
  1. Press ⌘+v to paste the contents of your clipboard. Done!

Note
You can open the current directory in your Finder by running open .. In fact, you can open most things (including files) with the open command. For example, you can open the text file you just created by running open revert.txt. This only works on macOS.)

The thing about these little nifty things you can do with the terminal is that their efficiencies add up. Being able to do this with one text file is nice, but having a whole library of text files you can do this with can potentially save you a lot of time. Plus, once you get used to it, navigating your filesystem using the terminal is a lot quicker, without the same distractions as clicking through the Finder, double-clicking and waiting for a file to open, and then realising its the wrong one and opening the next file (yes, I know QuickLook exists. I’m just trying to make a point).

Download YouTube videos

If you’re willing to really dig into this, you can install and run applications from the terminal directly. And I’d really recommend it, especially if you like YouTube and you’re tired of being endlessly assailed by ads when you try to google "YouTube downloader" (or worse, if you’re using a dubious ad-riddled piece of software to download these things). Enter brew.sh.

brew.sh is a package manager for macOS (there are similar things for Windows, but none come close to anything you can run in a bash terminal) that allows you to install applications by just running brew install <application_name>. Go to brewformulas.org [2] to find a list of applications you can install and run in the terminal.

Now, for the important part — start downloading YouTube videos by doing the following:

  1. Open the terminal.

  2. Install brew.sh by running this command displayed on their site. You’ll probably have to enter your user password to complete the installation. [3]

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. Install the youtube-dl tool. Run:

brew install youtube-dl
  1. Go to a YouTube video, and copy its URL from the browser’s address bar.

  2. Go to your terminal and run:

youtube-dl -f mp4 <youtube-video-url>
  1. Done!

Conclusion

The terminal is scary as it is powerful. Once you’ve gotten the basics down, you’ll be able to very quickly use more of its features. Plus, once you’re fluent with the macOS terminal, you’re essentially fluent in Linux (though I’m not sure how useful this is to you) because the macOS terminal and the Linux terminal both use the same command shell: bash.

This means lots of skills are transferable: you can read and write files in the same way, and do things like check your computer’s IP address by running ifconfig (deprecated in more recent versions of Linux).

This also means that you can quickly graduate to using more advanced tools, like the Hugo static-site generator, which this site is built on. But that’s a post for another time.

If you’ve got questions on how this possibly can help you at work or at play, you can email me at zed@nsdmdh.com.


1. cat is short for "concatenate", which also means you can run this on several files to display all their text as a single stream of output.
2. For some reason, the site is down at the time of writing.
3. This should work out of the box; you can email me with questions if it doesn’t.
Author | Zed is a former educator and currently a professional explainer. He writes about software, video games, and narrative design. If you have software or a system that needs explaining (to frustrated users, or you just need someone to write stuff down for you), you can contact him for work at zed@shootbird.work.

back · main · 打鳥 (shoot bird?) · hire us · blog