Unix Gems for Mac OS X
Pages: 1, 2, 3, 4
To change the format of the plot, you can use any one of GNUPlot's formatting
commands. Here are
some examples. (Switch your terminal back to aqua, set term aqua,
before running these commands).
gnuplot> set title 'Test Plot'
gnuplot> set style function linespoints
gnuplot> plot sin(x)
These example show how to create plots interactivity within GNUPlot. All of this requires a lot of typing. Another way to use GNUPlot is to save all your data and commands in files and tell GNUPlot to process the files to produce the plot. This is a very powerful technique since you can write code to generate these files on the fly and feed them to GNUPlot automatically.
Let's take a look at how this works. Imagine you are developing a program and would like to plot its CPU usage. To accomplish this, we need a script that captures the process' CPU usage and another script that takes this data and plots it using GNUPlot.
For this example, we'll use 3 programs. The first is called fibonacci, a C program that generates the fibonacci series. The other two programs are scripts that acquire CPU information and plot the data. One is called logger.py, which collects CPU usage while the fibonacci program runs and writes it to a file. The other script is called plotCPU.py. It writes a plot format file and calls GNUPlot to display the plot of CPU usage.
To use these scripts, you need to open two shells. In the first shell, compile
the fibonacci program
(gcc -o fibonacci fibonacci.c). Next, run the fibonacci program
by typing fibonacci at the prompt. While
fibonacci is running, type the command python logger.py fibonacci 1 >
fibonacci.dat in the second shell.
Once the fibonacci program exits, Ctrl-C out of the logging script. Finally,
run plotCPU.py to generate
the plot (python plotCPU.py).

There are lots of other things you can do with GNUPlot like generating 3D and multi-plot. If you ever need to visualize data, definitely check out GNUPlot. It's very powerful when combined with scripting languages like Perl and Python and is a natural addition to the development process.
Miscellaneous Programs
Before concluding, I'd like to mention two other programs I really like. The
first is called bc, an arbitrary precision calculator language.
If you are at the command line and need to perform some quick calculation, or
possibly need more power than the calculator that comes with Mac OS X, take
a look at bc.
The bc program supports arbitrary precision numbers and is great
for complex, as well as simple calculations. In addition to being an interactive
calculator, its also a language with a similar syntax to "C."
Here are some simple examples of bc in action:
% bc
12+54
66
x=2
y=3.123
z = x*y
z
6.246
scale=100
12/9
1.333333333333333333333333333333333333333333333333333333333333333333\
3333333333333333333333333333333333
scale=10
12/9
1.3333333333
z = 12/9
"z = "; z
quit
%
To exit bc, type quit or Ctrl-d. Take a look at the bc man page
and the resource section of this article
for more information.
A useful feature of Apple's TextEdit program is you can set it up to check spelling as you type. This way, if you misspell a word, you are notified immediately and can make the corrections right a way.
If you use Emacs for your writing, you can get the same functionally by using Flyspell. Flyspell is an Emacs minor mode that enables Emacs to perform spell checking and correction as you type.
Flyspell has lots of features. You can select your own dictionary, it works great with LaTeX, and can be set up to only check certain types of files. This way, it only checks your spelling for text and LaTeX files for example, and not source code; very useful.
Flyspell is very easy to set up so check its documentation for more information on installation and use.
Final Thoughts
There you have it, a look at some very useful Unix-based programs that you can use under Mac OS X. In this article, I only covered a few of my personal favorites. As you can imagine, there are lots of others waiting to be discovered. Check out the Resources section for information on where you can discover more.
Resources
GNU Screen
- GNU Screen: An introduction and beginner's tutorial
- Screen FAQ
- Power Sessions with Screen
- Installing and Using GNU Screen
Remind
GNUPlot
bc
Flyspell
Other Resources
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 13 of 13.
-
Gnuplot unavailable
2004-12-17 04:23:46 bfr [Reply | View]
Went to the fink link, installed, gnuplot is not listed. Followed your gnuplot links above, they lead to a non-existant dot-mac homepage. How did you actually get this to work? -
Gnuplot unavailable
2004-12-17 06:31:48 kom_14 [Reply | View]
gnuplot is available from fink. I just installed it using dselect to make sure (see trace that follows).
(9:14) (twoapple:omalley):omalley -: fink -v
Fink 0.21.3
(9:16) (twoapple:omalley):omalley -: gnuplot
tcsh: gnuplot: Command not found.
(9:16) (twoapple:omalley):omalley -: sudo dselect
( ** Selected gnuplot and install **)
Reading Package Lists... Done
Building Dependency Tree... Done
The following NEW packages will be installed:
aquaterm gnuplot pdflib-shlibs texinfo
0 packages upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 8078kB of archives. After unpacking 22.9MB will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.dl.sourceforge.net 10.3/release/main texinfo 4.7-11 [1264kB]
Get:2 http://us.dl.sourceforge.net 10.3/release/main aquaterm 0.3.0a-5
[50.4kB]
Get:3 http://us.dl.sourceforge.net 10.3/release/main pdflib-shlibs 5.0.1-2
[2224kB]
Get:4 http://us.dl.sourceforge.net 10.3/release/main gnuplot 3.8j.0-24
[4541kB]
Fetched 8078kB in 23s (340kB/s)
(Reading database ... 76054 files and directories currently installed.)
Unpacking texinfo (from .../texinfo_4.7-11_darwin-powerpc.deb) ...
Unpacking aquaterm (from .../aquaterm_0.3.0a-5_darwin-powerpc.deb) ...
Unpacking pdflib-shlibs (from .../pdflib-shlibs_5.0.1-2_darwin-powerpc.deb)
...
Unpacking gnuplot (from .../gnuplot_3.8j.0-24_darwin-powerpc.deb) ...
Setting up texinfo (4.7-11) ...
* Texinfo: (texinfo). The GNU documentation format.
install-info(/sw/share/info/texinfo): creating new section `Texinfo
documentation system'
* info standalone: (info-stnd). Read Info documents without Emacs.
* Info: (info). How to use the documentation browsing system.
Setting up aquaterm (0.3.0a-5) ...
Setting up pdflib-shlibs (5.0.1-2) ...
Setting up gnuplot (3.8j.0-24) ...
Do you want to erase any previously downloaded .deb files? [Y/n] y
Press enter to continue.
(9:17) (twoapple:omalley):omalley -: rehash
(9:17) (twoapple:omalley):omalley -: gnuplot
G N U P L O T
Version 3.8j patchlevel 0
last modified Wed Nov 27 20:49:08 GMT 2002
System: Darwin 7.6.0
Copyright(C) 1986 - 1993, 1999 - 2002
Thomas Williams, Colin Kelley and many others
This is a pre-version of gnuplot 4.0. Please refer to the
documentation
for command syntax changes. The old syntax will be accepted throughout
the 4.0 series, but all save files use the new syntax.
Type `help` to access the on-line reference manual
The gnuplot FAQ is available from
http://www.gnuplot.info/faq/
Send comments and requests for help to
<info-gnuplot-beta@dartmouth.edu>
Send bugs, suggestions and mods to <info-gnuplot-beta@dartmouth.edu>
Terminal type set to 'x11'
gnuplot>
-
bc is ancient
2004-07-14 10:57:26 oak [Reply | View]
Nowadays I've replaced bc with python. It has about everything that bc and can be programmed too.
-
missing ./
2004-07-08 23:27:59 Marti [Reply | View]
You forgot "./" before "fibonacci" in the running instructions.
-
installation
2004-07-08 13:33:13 fred76 [Reply | View]
Remind loks interesting, but where do you go for installation instructons? -
installation
2004-07-09 04:27:36 kom_14 [Reply | View]
Its simple (assumes developer tools, Xcode, is installed).
- Download the current version (remind-03.00.22.tar.gz)
- Open a Terminal window, cd the directory where the file is, and type:
% tar zxfv remind-03.00.22.tar.gz
- cd to remind-03.00.22 and build
% ./configure
% make
% sudo make install
If you do not have root access you can install it locally by copying the remind and rem2ps binary to a local directory, say ~/bin, and adding the directory to your path.
-
Useful tips
2004-07-08 02:53:47 Giles Turnbull |
[Reply | View]
Thanks, I enjoyed reading this article. Knowing how to use screen really helps on my iBook, where monitor real estate is often a problem.
-
Little to do with Mac OS X
2004-07-08 01:09:04 sanchonevesgraca [Reply | View]
I think most Mac OS X users, including developers, will find the programs you outlined rather outdated, and certainly having little to do with Mac OS X. Users and developers of Mac OS X use the BSD core, but expect a modern interface and modern connectivity options. There are quite a few layers on top of the Darwin kernel, for a myriad of concerns. There are indeed GNU programs that are gems. But I would not rate as gems screen (the window management of Apple Terminal is very good), remind (compare with Apple iCal), bc and GNUPlot (compare with Matlab, Mathematica or lighter alternatives). While these programs have their value, they are not really Mac OS X applications from a user point of view. For that, they would have to be wrapped with one or more of Carbon, Cocoa, WebKit, Dashboard, etc, with particular attention to user interaction. -
Maybe not for everyone, but...
2004-07-10 14:17:20 tomsax [Reply | View]
I've been a rabid Mac user and developer since 1984. I had been exposed to the Unix command line a few times, first using the Manx C compiler on a "fat Mac" in 1985. While I wouldn't trade the Mac GUI for anything else, I find the command line to be a nice addition to the graphical UI. I for one am always interested in learning how to be more productive by using the CLI for things it does well.
I enjoyed reading about each of these programs, please show us more.
That said, I'm zero for two so far.
Screen doesn't work quite as described: Ctrl-a does not bring up the list of windows. Also, Cmd-K (clear scrollback) doesn't work in a screen session. I use bask, maybe it works better with tcsh.
I downloaded remind and was able to configure and build it, but the install failed (even using sudo or su) until I manually created /usr/local/bin and /usr/local/man.
-
Listing displays command
2004-07-07 09:42:37 tshubitz [Reply | View]
In paragraph two on page two there is an error with how to list currently running displays. Instead of the mentioned Ctrl-a, type Ctrl-a " (that's a double-quote, you'll need to hit Shift-' [single quote]). Anyway. Rock on folks.
- tim





