Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

List of terminal commands

From time to time new users ask where they can find a list of Terminal commands.

Clearly there are many possible replies to this but I like these four:

1 - Short list: http://ss64.com/osx/

2 - Long list: http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/

3 - Use the excellent 'List pages' facility of ManOpen. Each item is a clickable hot link.

4 - Produce your own list:

Open Terminal and paste the following and then type return:

/usr/libexec/makewhatis

Wait for the prompt.

Paste the following and then type return;

apropos ' '

On a basic Leopard installation this produces over 4,000 lines with each line containing one or more manual references. If you want to use the list it may be best to set the terminal to 999 columns before you start. It is easy to page down (shift page-down several times) to the bottom, select all (cmd A), copy (cmd C) and paste into a fast text editor (I still use BBEdit Light).

It is possible, although the mass edits are not trivial, to make each item in this list a hot link with one of the following:

A - HTML: <a href="x-man-page://ls">ls</a> - opens the manual page for ls in your Terminal - should work with most browsers - perhaps try clicking it!

B - Manual page - pity the hot links don't work in the Terminal although they do with several other applications such as ManOpen - see groff_mdoc for further information.

.Dd
.Dt LIST OFLINKS
.Os
.Bl -item -compact
.It
List of Links
.It
.Xr whatis 1
- search the whatis database for complete words
.It
.Xr man 1
- list directory contents
.It
.Xr ls 1
- format and display the on-line manual pages
.It
.Xr groff_mdoc 7
- reference for groff's mdoc implementation
.El

Do others have better ways to view local manual pages with full scroll and hot links?

Xserve and two 733 MHz G4s with Leopard !, Mac OS X (10.5.8)

Posted on Apr 3, 2010 4:33 PM

Reply
32 replies

Apr 4, 2010 5:33 AM in response to Neville Hillyer

I cannot get your HTML script to do anything. No apparent errors but I cannot find any output.

My script should have generated a tmp.html file in the current working directory.

If you are saying you have a tmp.html file, but it is empty, that is unexpected.

That would say that awk did not find any matches to the selection string:

/(1|(6|(8/

And if there were a copy & paste error, it is more likely awk would have detected some kind of syntax error.

Anyway, I've reposted the little script with the modifications to not be overly agressive on what it selects.

#!/usr/bin/env bash
apropos ' ' | awk ' /(1|(6|(8/ {
match($0,/ - /)
cmd = substr($0,1,RSTART-1)
therest = substr($0,RSTART)
page = cmd
sub(/(.*/,"",page)
sub(/ *$/,"",cmd)
printf("%s%s
", page, cmd, therest)
}' >tmp.html
If you feel like pursuing this further, post your version of the script between a pair of
tags. For example:

...
... your version of the script here ...
...
{code}

Apr 4, 2010 5:51 AM in response to Neville Hillyer

Yes, often mentioned as the solution to everything but my concerns about it are:

1 - slow

I didn't think it was that slow (personal opinion). I'm unlikely to use it, as I just tend to use man, apropos, and Google, but when I tried the dcl example it completed very quickly.
2 - source hot links (Xr) not used

not sure what that means.
3 - too little info per screen due to large font and incorrectly interpreted source CRs - see my earlier post.

It didn't seem too bad to me, but again, I'm unlikely to use it, and besides it is more important how the reader likes the information to be displayed, so your #3 comment is perfectly valid.
4 - too much to type each time - I prefer the simplicity of m dscl

That is easily fixed by creating a script or an alias. For example:

#!/usr/bin/env bash
TMP=/tmp/$1.pdf
/usr/bin/man -t "$1" | pstopdf -i -o "$TMP"
open "$TMP"

Create a file with this script in it (call it mp). Make the script executable (chmod +x mp). Put the mp script in a directory contained in your PATH environment variable, or add a personal script directory to PATH.

Now it should be as easy as using the man command to get pdf'ed man pages.

mp dscl

Assuming you like the pdf styled man pages that is.

Apr 4, 2010 8:32 AM in response to BobHarris

I apologise - your HTML script was working - my quick look at my home folder (default directory) failed to see it as, unusually, it was set to date order. I don't know why I was expecting to see it on my desktop (my default download folder).

I am pleasantly surprised that the Terminal accepted this as a single copy/paste which saved me having to paste one instruction or line at a time.

This could be a very useful script for my type of exercise. In particular it is a trivial editing exercise to change the link styles with eg BBEdit. The semi HTML may not work with all browsers but, again, it is trivial to insert a proper HTML header and footer.

Apr 4, 2010 9:14 AM in response to BobHarris

Re 1 - slow:

Starting with Terminal open and all other applications closed this method took 15 seconds after hitting return in the Terminal. It also required a manual click on the PDF. Clearly this depends upon computer speed but it is common, while working with the terminal, to decide to look at a manual page. The time may have been extended by Adobe reader being set as my default PDF viewer. Under the same test conditions ManOpen took 3 seconds and Terminal took about 1.5 seconds.

Re 2 - source hot links (Xr) not used:

If you open an OS X manual file with a text editor you will see several lines starting with Xr. This is groff source code for hot links - see the manual page for groff. Several third party applications use these hot links. If the default OS X terminal recognised these links and had full scroll facilities few people would look elsewhere for manual viewers.

Re 4 - too much to type each time:

Thanks for this and your various other pieces of useful code.

Apr 4, 2010 9:29 AM in response to BobHarris

I have found your posts to be very useful.

I am beginning to wonder if there is a definition of OS X 'Terminal Commands'.

Perhaps wrongly I was working on the assumption that it included commands which would do anything if used in the Terminal. Any thoughts on this?

I was aware that apropos ' ' included most manual pages but could not see an easy way to reliably weed out only items not included in my definition. At least this method was not as bad as the long Apple list which includes manual pages for many items not on a standard installation.

Apr 4, 2010 10:01 AM in response to Neville Hillyer

Re 1 - slow:

Starting with Terminal open and all other applications closed this method took 15 seconds after hitting return in the Terminal. It also required a manual click on the PDF. Clearly this depends upon computer speed but it is common, while working with the terminal, to decide to look at a manual page. The time may have been extended by Adobe reader being set as my default PDF viewer. Under the same test conditions ManOpen took 3 seconds and Terminal took about 1.5 seconds.

I'll bet it was one of those "two 733 MHz G4s", and Adobe Acrobat Reader that caused the slowness.

On my 4 year old white MacBook 2GHz/2GB intel Core 2 Duo (with an upgraded 500GB 7200 RPM disk), it took about 5 seconds, including starting Preview. With Preview up and running, the next attempt took less than 2 seconds.

If on your systems Preview opens faster vs Acrobat, you could modify the open command to specify Preview, by adding a "-a Preview" option. See below:

#!/usr/bin/env bash
TMP=/tmp/$1.pdf
/usr/bin/man -t "$1" | /usr/bin/pstopdf -i -o "$TMP"
open -a Preview "$TMP"

However, if man pages in PDF do not provide the functionality you need, then this has just been an educational exercise which can often times provide benefits down the road.
Thanks for this and your various other pieces of useful code.

Your welcome.

Message was edited by: BobHarris

Apr 4, 2010 10:29 AM in response to Neville Hillyer

I have found your posts to be very useful.

I am beginning to wonder if there is a definition of OS X 'Terminal Commands'.

No. Actually thinking of commands as "Terminal" commands can lead you astray.

The Terminal is just a semi-dumb program that passes keyboard input to the Unix shell you are using (there are many Unix shells), and the Terminal displays text the shell, or commands run by the shell send to standard output and standard error. Besides that the Terminal does not do a lot more with respect to Unix commands.

The Shell (default is bash - Bourne Again Shell; named after Steven Bourne, creator of the first popular shell called the Bourne Shell or sh). Anyway there is also the ksh (Korn) shell, zsh shell, the csh shell, and the tcsh shell. There are most likely others, but these are the most popular.

Anyway, the shell is what gives the command prompt. It looks at the first white space separated thing you type as the command. If it is not a reserved statement (if/then/else/fi, case/esac, variable=value, etc...), or a build-in command (cd, export, set, print, echo, etc...), then the shell searches a list of directories stored in the PATH environment variable checking to see if the command you typed is the name of a file stored in one of those directories. If it finds a match, it creates a subprocess, and tells the operating system to execute that file. The operating system will determine if it is a program or a script and do the right thing.

The user can modify the PATH environment variable to include additional directories in PATH so that even more programs and scripts can be considered programs.

And if the command is not in PATH, then the user can always just type the full path to the program. For example:

/System/Library/CoreServices/Screen Sharing.app/Contents/MacOS/Screen Sharing

The bottom line is that there is no definitive list of Unix commands on any Unix based operating system.
Perhaps wrongly I was working on the assumption that it included commands which would do anything if used in the Terminal. Any thoughts on this?

I was aware that apropos ' ' included most manual pages but could not see an easy way to reliably weed out only items not included in my definition. At least this method was not as bad as the long Apple list which includes manual pages for many items not on a standard installation.

Actaully apropos only displays the man pages that are found via the MANPATH environmet variable when the whatis database was created, and if MANPATH does not exist, then the default man page directory list.

And even if you find every last man page and make sure the correct directory is in the MANPATH environment variable, that only covers commands which have man pages. Any commands/programs/scripts you create may not have man pages, and there 3rd party programs you might install that may or may not have man pages.

Then again, even if you do not find everything, you still have a lot of man pages at your disposal, 95% of you will most likely rarely if ever use. 🙂

Apr 4, 2010 12:04 PM in response to BobHarris

You are correct about the G4. It is surprising how well it normally works with Leopard - starting Adobe Reader is not one of its strong points.

I have little interest in anything without hot links especially PDFs but I tried your code and got:

bash-3.2$ /usr/bin/man -t "$1" | /usr/bin/pstopdf -i -o "$TMP"
No manual entry for
%%[ Error: ioerror; OffendingCommand: put ]%%
%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
%%[ Warning: PostScript error. No PDF file produced. ] %%
/usr/bin/pstopdf failed on PS read from stdin with error code -30998
bash-3.2$

Apr 4, 2010 12:30 PM in response to Neville Hillyer

You are correct about the G4. It is surprising how well it normally works with Leopard - starting Adobe Reader is not one of its strong points.

At this stage, we are just experimenting for the fun of it 🙂
I have little interest in anything without hot links especially PDFs but I tried your code and got:


bash-3.2$ /usr/bin/man -t "$1" | /usr/bin/pstopdf -i -o "$TMP"
No manual entry for
%%[ Error: ioerror; OffendingCommand: put ]%%
%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
%%[ Warning: PostScript error. No PDF file produced. ] %%
/usr/bin/pstopdf failed on PS read from stdin with error code -30998
bash-3.2$

That was suppose to be a script where you pass the name of the command you wish to get a pdf man page for

cat <<EOD >m2p
#!/usr/bin/env bash
TMP=/tmp/$1.pdf
/usr/bin/man -t "$1" | /usr/bin/pstopdf -i -o "$TMP"
open -a Preview "$TMP"
EOD
chmod +x m2p
./m2p cp
./m2p dscl
./m2p nano
./m2p find
etc...

Apr 4, 2010 2:18 PM in response to BobHarris

oops - sorry about that - I should have looked back at your earlier post.

It now works.

I put it in a file called m and did sudo chmod +x /usr/bin/m

Launch times are improved but not impressive. Without Preview open it takes 9 seconds which reduces to about half this with Preview open.

The display is very disappointing compared with Adobe Reader - thin sketchy font with touching characters - it is not clear to me if this can be changed.

Both Adobe Reader and Preview display as individual pages with annoying gaps, headers and footers.

Probably not worth pursuing but I was keen to see how it worked.

Apr 12, 2010 3:03 AM in response to Roberto SepĂşlveda

Please take a look at the Clix utility:

http://www.apple.com/downloads/macosx/systemdiskutilities/clix.html


Thanks for the interesting link.

I have spent over an hour playing with it:

1 - Installation and getting started information is scattered, incomplete and not where you expect to find it

2 - I cannot discover how to get it to accept any input in one of its windows

3 - Many useful pre-installed bits of code once you discover how to input your password which it calls a phrase!

4 - I have been unable to discover how to use it with ManOpen except to open the application

5 - I cannot see how to display its various options (installed code) from within the application.

In what way did you think it would assist me?

List of terminal commands

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.