Mar 10, 2014 Each Terminal window or SSH connection provides access to the input and output of a shell process. The examples in this book assume that you are using the standard OS X shell. (OS X Man Pages). You can also search the manual pages by keyword using the apropos command. Upgrading from OS X Snow Leopard or Lion. If you’re running Snow Leopard (10.6.8) or Lion (10.7) and your Mac supports macOS Mojave, you will need to upgrade. Mac OSX Server Command-Line Administration. The owner or authorized user of a valid copy of Mac OS X Server software may reproduce this publication for the purpose of learning to use such software. No part of this publication may be reproduced. Normally appears in a Terminal window, are shown in this font. The history of macOS, Apple's current Mac operating system originally named Mac OS X until 2012 and then OS X until 2016, began with the company's project to replace its 'classic' Mac OS.That system, up to and including its final release Mac OS 9, was a direct descendant of the operating system Apple had used in its Macintosh computers since their introduction in 1984.
If you’ve read Macworld for any length of time—particularly our OS X Hints blog or any other story that asks you to use Terminal—you may have wondered to yourself: How do you learn about all those mysterious commands, such as ls
or cd
? Is it some kind of arcane knowledge, handed down only to initiates after grueling initiations? Well, no. Actually, anyone can learn about Terminal commands, if they know where to look. Today, I’ll tell you where.
Man up
The key to Terminal wisdom is the man
command. It summons manual (or man) pages for almost any command; they’re the equivalent of a help system for the command line. In fact, man
itself is a command, whose role is to format and display this documentation.
First, launch Terminal (in your /Applications/Utilities folder). Then, if you type man pwd
, for example, Terminal will display the man page for the pwd
command.
All man
pages have a common format. They begin with name (the name of the command) and a brief description of what it does. The pwd
command I looked at above shows the following:
pwd—return working directory name
Next comes synopsis, which shows the command any any options, or flags, that you can use with it. For pwd
, there are two options: -L
and -P
. These options are explained in the description section:
As you can see here, each of the two options is explained, and a final sentence tells you that the command assumes that the -L
option is desired if no other option (and there’s only one) is specified.
As you work from the command line, you’ll find that reading up on the options available for different commands is really important. You’ll learn the myriad ways you can use these tools, and some man
pages also contain examples to help you understand them.
Paging man pages
When you look at a man
page, you do so in Terminal through another command, called a pager; by default, this is the less
command. What a pager does is allow you to view content in Terminal page by page, or line by line. When you’re viewing a man
page, you will most often not see the entire page at once. You’ll need to page down to see more.
There are two ways to do this with less
. If you press Return, the page will move down one line. And if you press the spacebar, the page will scroll one page (the number of lines visible in your Terminal window). You can tell that there’s more to come by the :
(colon) visible at the bottom of the window.
Try it on your Mac: Open Terminal, type man ls
, then press Return. The ls
command’s man
page is quite long, and you’ll need to press the spacebar several times to get to the bottom.
Sometimes, when you’re viewing a man
page, you need to go back up and look at something that’s no longer visible. Depending on your Terminal settings, you may be able to scroll the Terminal window. If not, press Control-B to go back a page, and the spacebar, or Control-F, to go forward a page.
When you get to the end of a man
page, you’ll see this: (END)
. You’ll notice that you can’t do anything at that point; you need to quit the less
command; do this by pressing the q
key.
Other ways to read man pages
If you don’t want to read man
pages in Terminal, there are other ways to view this content. Carl Lindberg’s free ManOpen is a simple app that lets you view man
pages in a more attractive way than in Terminal. Press Command-O, enter the name of a command, and click Open. ManOpen is especially useful because you can choose specific sections to view from a popup menu, and you can navigate more easily than in Terminal with the less
command.
But you can also find man
pages on the Web. Just type man
and the name of a command into your favorite search engine, and you’ll get plenty of hits. Apple has a documentation repository with man
pages here. You can click Alphabetic Index to get a list of all commands, then search for the one you want. Apple’s man
pages are useful because a popup menu near the top of the page lets you choose an OS X version, so if you need to see the man
page for an older version of OS X, you can do so.
No matter which route you choose, man
pages open the door to a goldmine of information about the command line. Use them and you’ll learn all the ins and outs of the commands you use.
The OS X Terminal is a very powerful tool for configuring and using a Mac, and can be used to script and program a number of aspects of the computer's operations; however, its text-based interface can be a bit of a cryptic environment to first-timers, especially when it comes to finding out what you can use it for.
There are thousands of Terminal commands available, but when you first launch it you might not have a clue where to look for them. Of course there are basic commands like 'ls' for listing directory contents or 'cd' for changing directory, but in addition there are text editors, string parsers, expression managers, and numerous other commands that, depending on the purpose, can make the Terminal a hidden but exceptionally powerful tool.
If you are just getting started with using the Terminal, you may find it useful to build your command vocabulary. There are many resources such as the BSD Unix command summary that will give you a quick overview of the common commands; another approach is to list all commands available to you and then look up the manual page of each individually to see what its purpose is and how it's used.
There are a number of ways to list all of the commands, but two quick ones are Tab completion and the 'compgen' command. For Tab completion, simply type something in Terminal and hit Tab once or twice (and if prompted, confirm that you want the options displayed) and the system will list all available commands based on the text you entered.
If you press the Tab key without having entered any text, then the Terminal will output all possible commands (after you confirm that you want it to do so). If you do this, it helps to make the Terminal window as large as possible. You can then press Enter to display more items that are off the page until you are dropped to the command prompt again, but then you can scroll up and down to review the commands that were listed.
Mac Os X Terminal Colors
The second option is to list the commands and aliases available to you using the 'compgen' built-in command. Simply type the following command, and you will be given the full alphabetical list of commands available to you in the system:
compgen -ca
You can also redirect the output to a text file on your desktop called 'commands.txt' to peruse later:
compgen -ca > ~/Desktop/commands.txt
Referring to this list of commands, you can then look each up using the Terminal commands 'man' for the full manual page or 'whatis' for a brief synopsis of what it does. For instance, unlike the command 'diskutil' it may be difficult to guess what the command 'xattr' does from its name, so you can quickly look this up by running the following:
whatis xattr
Note: If the whatis command is not working then run the command '/usr/libexec/makewhatis' in the Terminal.
Mac Os X Terminal Commands
You can find more information and specifics on how to use the command through its manual page. There are a number of approaches to viewing a manual page for a command, with four that may be most useful:
- The man command
The default way to view a manual page is to use the man command the way the whatis command is used above, which will bring up a formatted instruction manual for the command that you can navigate through with the arrow keys or the F and B keys (for forward and backward). For example, to view the manual page for the xattr command, you would run the following:man xattr
To quit the manual page, simply press the Q key. - The 'xman' command
If you have XQuartz installed or Apple's provided X11 windowing system for Unix (provided by Apple in OS X Lion and previous versions), then you can run the 'xman' command to open up a manual page browser that you can click through. This is a quick and convenient way to not only view the manuals, but also see the available commands. - The Web
A third resource is various Web sites that contain collections of man pages for commands. An easy approach is to simply do a Web search for 'man COMMAND;' however, this may bring up platform-specific manual pages that do not completely pertain to the command in your version of OS X. A more Mac-specific man page collection is Apple's OS X Manual Pages site. - Third-party man page utility
A final option is to use a third-party manual page tool, such as OnyX, which contains a full man page browser. Like the xman utility, this will give you a quick way to view available commands and study their manual pages. In addition, OnyX provides an option to save the manual pages as PDFs.
Mac Os X Terminal Manual Download
Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.