Skip to main content
X

Send us a Topic or Tip

Have a suggestion for the blog? Perhaps a topic you'd like us to write about? If so, we'd love to hear from you! Fancy yourself a writer and have a tech tip, handy computer trick, or "how to" to share? Let us know what you'd like to contribute!

Thanks for reaching out!

Tech 101: Introduction to the Mac’s Terminal App, Part One

Terminal may be one of the least used but most powerful apps included with a Mac. At first glance, Terminal seems to be the antithesis of the Mac’s friendly GUI (Graphical User Interface), presenting instead a simple command line interface that harkens back to the days of glowing CRTs with green, amber, or whitish text, connected to some distant computer system.

(The default Terminal window, with black text on a white background.)
(The default Terminal window, with black text on a white background.)

The Mac’s Terminal app emulates the old terminals, and provides access to a UNIX shell, where you can issue commands to manipulate the UNIX system that underlies the Mac OS. The UNIX shell, in this case, a Bash shell, provides a command processor that can interpret text entered by the user. It’s not just simple text commands you enter, such as displaying the contents of a folder, that the Bash shell can process, but also scripts, chains of commands, piping, conditional testing, variables, and more. The entire syntax that the Bash shell understands is a bit beyond this article. If you’re interested in creating shell scripts, Apple provides a developer’s guide to scripting using Terminal and the various UNIX shells.

In the first part of our introduction to Terminal, we’re going to look at Terminal with an eye to more basic usage, primarily as a way to modify the standard behavior of the Mac OS. We’ll also look at some basic file system manipulation as examples of ways to use Terminal. So, let’s get started with how to launch and configure Terminal for your use.

Launching and Configuring
The Terminal app is located at /Applications/Utilities. You can launch Terminal just like any other Mac app. Once launched, Terminal will display a window containing a title listing the current working directory, usually your home folder, the type of shell in use, such as Bash, and the window size in characters, such as 80×24 (80 characters across and 24 characters or lines down).

The working area of the Terminal window will initially contain just a few lines of text. On my Mac, it displays the last time I logged in (used Terminal), and then the Terminal command prompt, which consists of my Mac’s name, the current directory, and the currently logged in user, ending with a $ prompt.

Just after the $ prompt is a dark rectangle that serves as Terminal’s cursor, showing the current location at which text will appear.

(Terminal after issuing the cd .. and ls commands. Note the window has been customized with a different background color.)
(Terminal after issuing the cd .. and ls commands. Note the window has been customized with a different background color.)

Let’s try our first Terminal command. At the prompt, enter:

cd ..

Then press enter or return on your keyboard.

Nothing much happened, although if you look at the Terminal window title, it changed to say Users. If you look at the prompt, it changed to show that the current working directory has changed to Users.

That’s because the cd command means to Change Directory, while the .. tells the command to go up one level in the directory hierarchy.

Let’s try one more command, and then move on to some Terminal configuration options.

At the prompt enter:

ls

Press enter or return.

This time, the Terminal window will produce a list of items found in the Users directory. On my Mac, I see a Shared folder, along with three user account folders. If you wanted to examine any of these folders, you could use the cd command we tried earlier, such as cd Shared. Please note Terminal is case sensitive, so Shared is not the same folder as shared. Once you’ve moved to a new folder, use the ls command to view its contents.

OK, let’s move on to getting Terminal to look and operate the way you want it to.

Customize Terminal
Terminal has a number of customization options that you may wish to take advantage of, starting with the basic background color and text color. Terminal comes with a number of predefined profiles that set the colors used in a Terminal window. You can try each one out by selecting Shell, New Window, and then selecting a profile name from the menu.

(The Inspector is an easy way to select one of the predefined profiles for the Terminal window.)
(The Inspector is an easy way to select one of the predefined profiles for the Terminal window.)

There’s an easier way to examine the various profile settings, without having to open multiple Terminal windows; instead, select Shell, Show Inspector. In the Inspector window, click the Settings button. Every premade profile will be shown; you can click on a profile and the current Terminal window will change to show the new scheme. Go ahead and click through the various profiles until you find one you like.

If you would like to always have your Terminal window use a specific profile, here’s how to do it:

Select Preferences from the Terminal menu.

Select the General button in the Preferences toolbar.

Select On startup, open: New window with profile:

In the drop-down menu, select the Profile name you would like to use. You can always go back to the Inspector window to find the profile name you wish to use.

You can further customize a profile by selecting the Profiles button in the toolbar.

Select the Profile you wish to customize.

Click the Gear button, and select Duplicate profile.

Give the duplicate profile a new name.

(Profiles can be modified or new ones can be created using Terminal Preferences.)
(Profiles can be modified or new ones can be created using Terminal Preferences.)

The new profile will be based on the previously selected profile. You can now make changes without adversely affecting the original. We encourage you to experiment with the various settings. You can change text size, font, and color, background color, cursor style, and window size. While it’s OK to look at all the settings that can be changed, try limiting your customization to text, cursor, and window coloring for the time being. As you become more proficient with Terminal, other settings can be adjusted to meet your needs.

Now that you’ve seen that Terminal can be customized to your needs, let’s take a look ahead to part two of our Terminal series.

More About Bash and Commands to Customize Your Mac
In the second installment of our miniseries on Terminal, we’re going to take a more detailed look at the Bash shell, including some tricks that make entering and repeating commands a simpler process, and how to create a simple script. We’re also going to take a look at a number of commands that can be used to customize your Mac, including the “defaults” system used by the Mac to store system and application preferences. You’ve probably seen the defaults command mentioned in various Mac tips and tricks that involve using the Terminal app.

Before we move on to part two of our Introduction to the Mac’s Terminal App, we’re going to leave you with an example of the defaults command you can try out right now.

Modify the Dock to Include a Recent Items Stack
As far as the Mac OS is concerned, the Dock is just another app. As such, it has a number of preferences we can manipulate using the defaults command. You’ve already been using the defaults command every time you opened the Dock’s preference pane and made a change. In the background, a defaults command is executed to change a preference.

(The Terminal window after the defaults command is used to modify the Dock with a new Recent Items stack.)
(The Terminal window after the defaults command is used to modify the Dock with a new Recent Items stack.)

In this example, we’re going to change a preference that will enable a Recent Items stack to be created in the Dock and marked as persistent, so it will stay in the Dock from restart to restart.

At the Terminal prompt, enter the following:

defaults write com.apple.dock persistent-others -array-add ‘{ “tile-data” = { “list-type” = 1; }; “tile-type” = “recents-tile”; }’

You can triple-click the line above to select it, and then copy/paste the command into Terminal.

Press enter or return to execute the command.

You’ll need to restart the Dock application so it will read the changes to its preference files.

Enter the following text into Terminal:

Killall Dock

Press enter or return.

The Dock will relaunch itself. Look on the right-hand side of the Dock, near the Trash icon; there should be a new stack named Recent Applications. If you don’t wish to keep the Recent Applications stack, you can drag it from the Dock to the Desktop to delete it.

See you next week for part two of our Introduction to Terminal.

Tom Nelson
the authorTom Nelson
Writer
Tom has been an enthusiastic Mac user since the Mac Plus. He’s also been known to dabble in the dark side, otherwise known as Windows, and has a well-deserved reputation for being able to explain almost anything to anybody. Tom’s background includes more than 30 years as an engineer, programmer, network manager, software tester, software reviewer, database designer, and computer network and systems designer. His online experience includes working as a sysop, forum leader, writer, and software library manager.
Be Sociable, Share This Post!

Leave a Reply

10 Comments

  • Tried this but get a parse error; is this something about zsh that’s different?

    tpb9k@M1MBP14 ~ % defaults write com.apple.dock persistent-others -array-add ‘{ “tile-data” = { “list-type” = 1; }; “tile-type” = “recents-tile”; }’
    zsh: parse error near `}’

  • The Recent stack created with the defaults command is not just for apps. Once it’s created on the Dock as described, right-click it to change to Recent Documents, Recent Servers, Favorite Volumes, or Favorite Items. Its contents can also be viewed as Grid, List, or Automatic (default).

  • Thanks to all who comment on this great OWC Reviews. I wonder if and what commands I may insert to assist with my iMac that has 32GB or memory and 2TB of storage, Yet I can’t even download a single video, U-tube or Demo Video Without rebuffering six or more times! Also my ISP is Hughes Net. Does anyone have a suggestion as to what commands may work to assist me? Thank you in advance for any response.

    • I have a similar configuration as yours; but only 1TB of storage. Also have too many spinning beach balls.

      Any good suggestions from those smarter than us?

  • Thanks for the Blog…had to tweak your command so it would work for me.

    defaults write com.apple.dock persistent-others -array-add ‘{“tile-data” = {“list-type” = 1;}; “tile-type” = “recents-tile”;}’;

  • Happy to see this series. Been a MAC user since the Nineties. Always wanted to experiment with Terminal but was afraid to screw up my computer. Hope these lessons will ease my concerns.

  • I like the idea of the “recent apps” in the dock. Very useful.

    However, copy/pasting your command I got a bash syntax error.
    -bash: syntax error near unexpected token `}’

    I found another post (TekRevue – guide to customizing the dock) describing the same thing and the only differences were a) the single quotes appear different and b) the use of code tags in the post. The below command worked for me.

    defaults write com.apple.dock persistent-others -array-add ‘{ “tile-data” = { “list-type” = 1; }; “tile-type” = “recents-tile”; }’

    Many thanks! A very useful blog!

  • I wish that more people would make friends with the Terminal app and the command line. There are so many things you can do there that are harder to do (or impossible) in the GUI.

    (I speak this as an old ‘computer salt’ who has been using them since 1974 on multi-user DEC PDP-8, DECsystem-10s, etc. using Teletypes (never mind green-screen CRT terminals). My day job is release engineering at Red Hat [which has a fairly significant Mac presence], and my Mac there usually has anywhere from 10 to 30 Terminal windows open connected to various Linux computers.)