Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This
This chapter is from the book

Exercise 4.1 Command-Line Navigation

In this exercise, you use commands to navigate the file system, to view items that aren’t visible from the Finder, and to access the manual (man) pages that tell you more about commands.

View Your Home Folder

  1. If necessary, log in as Local Administrator.

  2. Click Launchpad in the Dock.

  3. In the Search field at the top of the screen, enter Terminal.

  4. Click Terminal.

    A new Terminal window opens.

    The second line you see includes your computer and user name followed by a prompt—for example:

    Mac-17:~ ladmin$

    In this example, Mac-17 is the name of the Mac you logged in to. The colon separates the computer name from the path to your current working directory. The path is ~ (the tilde [~] is shorthand for your home folder). After the space, you see the name of the logged-in user. The $ is the prompt.

  5. At the prompt, type ls and press Return.

    You will see output that looks something like this, followed by another prompt:

    Desktop     Downloads           Movies   Pictures
    Documents   Library   Music    Public
  6. Switch to the Finder. If you don’t see a Finder window that’s open, go to File > New Finder Window or press Command-N.

  7. Select ladmin’s home folder in the Finder sidebar and compare the contents of the home folder in the Finder and Terminal.

    With the exception of the Library folder, what you see in Terminal is the same as in the Finder. (User Library folders are hidden in the Finder by default; see Reference 14.1, “Examine Hidden Items.”)

  8. Switch back to Terminal and type ls -A (lowercase LS followed by space, a hyphen, and an uppercase A) at the prompt.

    In general, the command-line environment is case-sensitive. For example, ls –a isn’t the same as ls -A.

    You will see some extra files in the list that begin with a period. Files beginning with a period are hidden in directory listings unless you ask for them by entering ls -A. The Finder doesn’t show files beginning with a period (sometimes called dot-files).

Examine and Change Your Current Working Directory

Think of your current working directory as the place you are in the file system. When you open a new Terminal window, your default working directory is your home folder. Use the cd command to change your current working directory.

  1. At the prompt, type pwd.

    The period (.) ends the sentence and isn’t part of the command, so don’t type it. This guide tells you if a trailing “.” is part of the command. Also, press Return at the end of each step, unless otherwise instructed.

    You will see:


    This is where Local Administrator’s home folder exists in the file system. It’s the folder you’re “in” in this Terminal window.

  2. At the prompt, type cd Library.

    This changes your current working directory to the Library folder inside your home folder.

    This command uses a relative path. A relative path means “Start in my current working directory.”

    Your prompt changes to something like this:

    Mac-17:Library ladmin$

    The path component of the prompt indicates the folder you are in, not the entire path.

    The cd command changed your working directory without providing feedback. A command that completes and doesn’t need to provide feedback will exit silently. If you get an error message, you should investigate its cause before continuing.

  3. At the prompt, type pwd. Terminal displays:


    You changed to the Library folder that was inside your previous working directory.

  4. Type ls to view what files and folders are in this Library folder.

  5. At the prompt, type cd /Library. Note the / that precedes Library this time.

  6. At the prompt, type pwd. You will see output like this:


    This is a different folder.

    A path that starts with a leading / is an absolute path. It means “Start at the root folder and navigate from there.” A path that doesn’t start with a leading / is a relative path. It means “Start in your current working directory and navigate from there.”

  7. Enter ls to view the files and folders that are in this Library folder.

    There is some overlap in the item names in this Library and the one in ladmin’s home folder, but the names aren’t entirely the same.

  8. At the prompt, type cd and a space character. Don’t press the Return key.

    Terminal enables you to drag and drop items from the Finder to Terminal and have the path to the items appear in the command line.

    In this part of the exercise, you use the Finder to locate a folder you want to use as your working directory in Terminal.

  9. Switch to the Finder.

    When you don’t know exactly what you are looking for, it’s sometimes faster and easier to find a file or folder in the Finder.

  10. Open a new Finder window if necessary.

  11. Click Macintosh HD in the sidebar.

  12. Open the Users folder.

  13. Drag and drop the Shared folder to Terminal.

    Terminal fills in the path (/Users/Shared). Macintosh HD doesn’t appear in the path that Terminal fills in.

    The Finder shows you volume names to make locating a particular volume easier. Terminal doesn’t show volume names in the same way.

  14. Switch to Terminal and press Return.

  15. Type pwd at the prompt.

    You are in the Shared folder.

Read About ls in the Man Pages

In Terminal, you can read the details about commands using the man command.

  1. Open Terminal.

  2. At the prompt, type man ls.

    This opens the man page for the ls command.

    Each man page is divided into various parts. The number in parentheses on the top line indicates in which section of the manual this command is documented. In this case, ls is documented in section 1, which is for general use commands. Next you see the name of the command and a very terse summary of what the command does: “list directory contents.” The synopsis is supposed to be a formal representation of how to use the command. Anything contained in square brackets is optional. The synopsis isn’t always completely accurate. For example, a few options for ls are mutually exclusive of each other, but this synopsis does not indicate that. Generally speaking, options or switches (which change the behavior of a command) immediately follow the command, and arguments (which tell the command what to operate on) follow options or switches. The description, which describes the various uses of the command, follows the synopsis.

  3. Press the Q key to quit viewing the man page for ls.

  4. At the prompt, type man less.

    The less option enables you to view one man page at a time.

  5. Use the Space bar to read through the man pages one page at a time.

  6. After you’re comfortable with the less option, read the ls man page.

  7. At the prompt, enter man man.

  8. Read about the man command.

    You can also Control-click, or on a MacBook Pro with Touch Bar, tap the icon for a man page to open it.

  • + Share This
  • 🔖 Save To Your Account