BluaP Mac Support
Mac Nieuws BluaP Mac Support Weblog Software Mac Games Nieuws & Downloads WiFi / Airport / 802.11
Te Koop Aangeboden (en gezocht) Mac Knowledge Mac Tips Unix Mac Links


Introduction to Darwin, part 1



Introduction
Mac OS X is based upon a *nix kernel called Darwin, and that is what makes OS X so great. Yet you, as a long time Mac user, don't have a clue as to what this really means or how to take advantage of it. Well, read on and we'll run you through the basics and teach you how to handle the basic *nix stuff.

In this tutorial, "quotes" are used to show commands. When typing them in, you will not type in the quotes and you will type in everything in them exactly. Any punctuation that would normally be within the quotes in the sentence due to normal American grammar will have been moved outside of them for this tutorial. Needless to say, you will have to hit RETURN afterwards. <Carrots> show something that will be replaced. The item that should do the replacing will be named in between the carrots and the carrots themselves are not carried over to the final version. Keystrokes with names will be put in brackets such as [RETURN] or [CONTROL].


Unix - a history and definition
UNIX was created by Bell Labs in an effort to make a robust computer operating system that would allow for multiple users and multitasking. From there it was licensed to various companies and universities where it was modified into their own use. All of these separate OSs that evolved from the original UNIX code as well as others that sought to perform the same original goals but evolved separately, such as GNU and Linux, are known as *nix OSs. It all gets very complicated very quickly and you can follow the history yourself on the chart below (Darwin is listed) as well as follow links posted there to some very good pages about UNIX history.

See also: http://perso.wanadoo.fr/levenez/unix/


Mac OS X's kernel - FreeBSD
One variant of this code was BSD developed by Berkeley, who ended up in legal battles with Bell over use of the UNIX code. From there, they stripped out all the code that Bell owned and ended up with BSD-lite which went on to become FreeBSD as well as other BSD OSs. Mac OS X's Darwin uses the FreeBSD as well as the MACH kernel. The symbol for FreeBSD, much like Linux has the penguin, is a little devil. Do not be surprised if you start seeing little devils popping up around Mac OS X related items.

See also: http://www.freeBSD.org


What is a kernel?
The kernel is the main engine of the computer. It is all the machine code that actually performs the actions you type in. Think of it like the engine of a car. You may drive the same model car and give the same commands through the steering wheel and foot pedals, but if it has a different engine it, it's going to perform differently.


Mac OS X login
With Mac OS X is you are probably going to have to login. Apple has been preparing Mac users with Multiple Users for awhile now. When you login, you enter a login name and a password which tells the computer who it is that is using the computer and how much control over the computer they get. You entered a login and password when setting Mac OS X up. This is an administrator login and gives you as much control over the computer as possible short of being "root".


Who or what is root?
Root, besides being the topmost level of the directory structure, is the computer's superuser. Root can do anything and see anything. In the *nix world there are some things which can only be preformed while logged in as "root". When you set up your computer, the root account was given the same password as your administrator account. If you login as root and look around in the console, you'll probably be able to see some files you can't normally see beginning with ".". These are all the secret hidden files that the Mac has always hidden and PC users have bitched about not being able to see. WARNING: It is a common mantra among *nix people "I must remember never to work on my computer as root." As root, you can seriously mess up your computer and should as a rule of thumb never login as root unless you have a good reason to. Any warning you ever heard about working in ResEdit on a Mac, you may now bring over and apply to working as root.


Mac OS X Terminal - tcsh shell
Open the Desktop, go into Applications, and go into Utilities. In there, you will see the Terminal application. Open it. You should end up with a window titled "/bin/tcsh" and with something like" [localhost:~] <username>% <cursor>" in the upper left hand corner. The window is known as the shell (the tcsh shell to be precise) and the stuff in the corner is the prompt. These are otherwise known as a Command Line Interface (CLI) meaning all commands are done through the keyboard (i.e., the mouse doesn't work here).


What is a shell?
Although the kernel does all the work, you need a way to tell the kernel what to do. The program that takes your commands and gives them to the kernel is called the shell. There are many shells, and different shells have different commands. Some have more and some have less. Some like the commands to be spelled all the way out and others like to make the commands as short as possible. Thus "changedirectory" and "cd" may have the same function in different shells. Which shell is better is another thing that *nix people argue about when not putting down Windows and Mac people. Mac OS X comes with the tsch shell.


Mac OS X console commands
So you're in a Terminal session, what can you do now? (Note to people who have used DOS: this is going to look familiar and possibly bring back bad memories, but just keep telling yourself, it's *nix.) The prompt is going to tell you two things: where you are in the directory structure and who is logged in. After the prompt, where the cursor is, you can type in commands and enter them by hitting the RETURN key. You can run a program by entering the name of the program and hitting [RETURN]. The main thing you are going to do at the command prompt is navigate the directory structure. Type "ls" and the contents of the directory you are in will be printed out in the screen, and a new prompt will appear below ready for a new command. If you type "cd <directory name>" you will enter that directory if it is located in the current directory. This will be shown in the first part of the prompt. Type "cd.." and you will move one directory up.

Another command that will come in extremely handy is "man". This opens man files. Thus when you type "man tcsh" you open up the man file for the tsch shell.


What is a MAN file?
A "man" file stands for a "manual" file. Whenever somebody creates an application or command, they should create a man file for it. This file is instructions on how to use that application or command. In the terminal window, type: "man <command name>" and the manual for that command will show up. At the bottom of the console will be the path and the percentage already viewed. [RETURN] will move the document one line forward. [SPACE] will perform the page down function. [CONTROL] C will take you back to the shell prompt. Reading these can sometime be very helpful, however remember that they were most likely originally created by serious computer geeks for other serious computer geeks. Some are very well thought out and incredibly long, while others are almost non-existent and no help at all unless you already know what you're doing.

Try opening a console and typing "man man". This will be the manual for the man command.


Mac OS X applications
One thing people are happy about is that OS X comes with some basic *nix programs. There have always been a good deal of basic programs that have been viewed as essential on any *nix computer. Text editors, network tools, etc. Although the basic OS X is missing a compiler (the thing that turns typed out computer programming into the actual machine language the computer can run) which some people consider essential, it does have more basic programs such as PICO.


What is PICO?
PICO is your basic *nix text editor. It is about as basic as you can get. Your mouse isn't going to work and everything is done through keyboard commands. Luckily, most of the commands are displayed down at the bottom of the console screen. There are other basic text editors such as VI and EMACS for almost all *nix systems. You think Windows/Mac people argue? You should hear serious *nix geeks argue the advantages of their favorite text editor since that's where 99% of all *nix work is done.

Open a console and type "pico". You should now see a line at the top saying "UW PICO(tm) 2.3" and various commands at the bottom (the "^" stands for CONTROL), along with a cursor in the screen. Type "hello world" or something equally inane. Type "[CONTROL] O" to tell PICO you want to save the file. At the bottom you should see a "File Name to write:" and if you type, your characters fill in after this. This is the process for naming your file. Hit [RETURN] to save it to the directory you were in when you started PICO.

Notice that [CONTROL] G is listed as help at the bottom of the page. You will need it.


Mac OS X Unix projects
Getting the hang of things yet? Let's try some other project.

How do you install the BASH shell?

Although Mac OS X comes with the tcsh shell, linux uses the bash shell and no doubt, you're going to hear about it. There should be lots of books and tutorials on linux, so lets change our shell to bash, so they'll make more sense on the Mac OS X Terminal.

Go to: StepWise and download the bash.pkg.tgz.

It should download to your Desktop. The version of StuffIt that came with Mac OS X is going to open and expand it.

You should now have three files on your desktop.* bash.pkg.tgz, bash.pkg.tar, and bash.pkg. Throw away the bash.pkg. Stuffit still has some problems, it seems.

Open up a terminal session. Type in "cd library/desktop". This will take you two levels down from your default directory to the desktop files. You can type "ls" to make sure that the "bash.pkg.tar" is there. Type in "tar -xvf bash.pkg.tar" ("tar" is the *nix program that compresses and uncompresses files like StuffIt. "-xvf" are switches that tell it that you are uncompressing a file and how to do it. "bash.pkg.tar" is the file you are uncompressing.) A new bash.pkg should appear on the desktop.

Now click on the bash.pkg. This should start the Mac OS X Installer app. Once you have the Installer app running, you should notice that it says, "You need an Administrator password to install the software" even if you are logged in as the administrator. It just wants confirmation that this install really is authorized. Click the little closed lock button in the lower left-hand part of the screen. A User Authentication window should appear and re-enter the administrator login and password. The lock will change to open, and you will then be able to continue and instructions will lead you through the install.

Once done, you can run the bash shell. You can do this by opening up a terminal window and typing in "bash". Your prompt will change from the usual to "bash-2.03$". You are now in the bash shell. You can change bash to your default shell by opening up the Terminal preferences and changing the shell variable to "/bin/bash".


Conclusion
You should now be familiar with some of the terminology and commands of *nix operating systems. Enough to adventure on with some idea of what you are doing. Read some of the man files. Look for Help commands. Experiment. Perhaps you can pick up a book on Linux or find more advances tutorials on the web and carry them over. I suspect that since CLI have such a following outside of the Mac community that this part of the Mac OS X will be expanded upon a great deal.

* I currently am having trouble seeing some *nix intended files in the Desktop. You can check to see if they are there for real using the Terminal. They can be seen usually with another app like text edit or StuffIt. Once opened, if you click on the Desktop real-estate, those files should appear.


< to part 2 >

----