|
Page 1 of 2
Since Mac OS X is based
on BSD Unix,
one of
the oldest and most stable UNIX platforms around (splintered from the original
UNIX developed by AT&T no
less),
Apple started a small coupe. Not only did they get Windows
switchers coming to the Mac, but they got many Linux switchers as well. The
simple reason is that now there is a beautiful front end to UNIX while
retaining all of its features and power.
Apple made no attempt to lock this feature out of the hands of the power user.
An offshoot of this is that Mac users are now open to a huge supply of Open
Source software. So how do you get these tools and applications on to your Mac
when so much of it is uncompiled source code? Do you have to be a developer or
experienced geek to be able to do it?
Well, you don't have to be a developer to get the software installed (although
it does help) but you will need to have the Developer Tools that Apple ships
with Macs and Mac OS X. If you don't have it then register on the Apple
Developer site and download the XCode software. Be warned though, it's
900Mb so be prepared to wait. If you have dial-up go to your nearest Mac
Dealer and ask for a copy. They might be able to
help.
For this tutorial I will be using Darwin
Ports,
a
packaging system for installing software from source code or
binaries. I used to use
Fink but it has had very little development lately and also it tends to do
things in a non-system way
by installing
things into a different directory structure that isn't officially supported by
Apple.
A brief explanation of the
commands
Before we begin I'll give you a very brief rundown of
what the commands do. This is not an in-depth look. For that use the MAN
<command> as mentioned in this section.
Terminal should be embraced. But for those who
grew up under the Mac OS 9 and below regime you'd never have had the
opportunity to get your hands dirty. As such this new experience can
be somewhat daunting. Please note, these commands, if used incorrectly, can be
very dangerous. However in this tutorial they are pretty safe.
SUDO: Sudo runs
tasks as the root user but not in a way that you can see the root user. By
default the root user is disabled under Mac OS X for security reasons. The
reason for this is because root is God in UNIX. Root is not limited by
anything and thus has the ultimate power to create or destroy. As you can
imagine, anyone with this type of account access can be very dangerous. Sudo
fakes the root user account giving your account power but only for the task at
hand. You still need to have an administrator account but these types of
accounts are still less privileged than root.
CD: CD stands for
"change directory". It's a pretty self-explanatory command. CD has a number of
accesses though. In this tutorial you will see a couple of them so I will
explain these:
cd /opt/local/var/db/dports: This
changes the directory to "dports" which can be found in the "db" directory
under the "var" directory which is in the "local" directory which hangs out in
the "opt" directory which can be found at the root of the system.
cd /: This isn't used in this tutorial
but it changes the directory to the root or base directory. This is the lowest
level you can get to.
cd ../: This changes the directory to
one level lower. In the first instance of CD shown above you will be taken
from the "dports" directory to the "db" directory. You can have as many "../"
as required and each will drop a directory. For instance "cd ../../" in this
example will drop you back to the "var" directory from the "dports"
directory.
cd ~/: This will take you to your home
directory. This is the shorthand version of using "cd /Users/lowededwookie".
Incidentally you can also get to your home directory by merely typing cd with nothing else after it.
One thing to note. While not a problem in this tutorial
if your directory has spaces in its name, you will need to use quotation marks
like so:
cd "test
directory"
The reason for this is that if you don't use quotations
it will try to change to the directory "test" which doesn't exist or it may
exist meaning you go into the wrong directory. For this reason, if you are
going to spend any length of time in Terminal then don't use spaces in your
names. It's better to use underscores like so:
mkdir
test_directory
CHMOD: This changes the permissions of
files and directories. Be careful with this command as changing permissions on
certain files will break the system. This command uses a series of 3 numbers
that affect the owner, the group, and everyone else. It sets the file's
read/write/and execute bits. 777 is pretty much full read/write/execute and is
shown like R/W/X when doing a directory listing. The values are calculated as
such:
| Execute: |
1
|
| Read: |
2
|
| Write: |
4
|
| Total: |
7
|
This is repeated for each of owner, group, and other and works like
this:
Owner: Read/Write = 6 (2 + 4)
Group:
Read = 2
Other:
Read = 2
So you would then use the command:
sudo chmod -R 622 bob
There is a switch here shown as "-R". This makes it a
recursive change of mode meaning that any files and directories in "bob" will
be changed even directories and files within directories until it gets to the
highest level. NOTE: switches are case sensitive. "-R" is
DIFFERENT to "-r"
MKDIR: This is the
make directory command. This is pretty much self explanatory. It's syntax
is:
mkdir
bob
MV: This means move
the file or directory. It's written in the format mv source
destination. Let's look at the example in this tutorial:
mv ~/Public/Portfile.txt ./Portfile
This is saying, move the file called "Portfile.txt"
found in the Public folder of the user's home directory to the current
directory and rename the file to "Portfile" (i.e. remove the .txt
extension).
You can move directories as well. For example you could
use this command:
mv -R ~/Public ./
This will move the Public folder located in the user's
home directory and everything in it to the current directory. Note that
this is a MOVE not a copy. It will remove it from the original location and
place it into the destination.
You'll notice that this command also supports the -R
switch like the chmod command. Like many commands in UNIX they will share
switches and these switches will work the same for each command, in this case
the recursive switch (-R) moves all the files and folders in that
directory.
To do a copy you would use the command
CP instead of MV. The syntax is the same.
All these commands are installed by default in Mac OS X
and in fact Mac OS X could not function without them. For instance when you
install a piece of software via the Package tool, when it asks for your
password it is in fact using the sudo command. When you copy
or move files within the Finder it is actually using the cp
or mv commands respectively in the background. Copying or
moving directories in the Finder uses the -R switch.
But in this tutorial there is another command:
Port: This is the
Darwin Ports installer tool. The line:
sudo port -d selfupdate
Tells Darwin Ports to update itself if updates are
available.
The command:
sudo port install xscorch
Tells Darwin Ports to install XScorch with any missing
dependencies as the root user.
There are a couple more commands that I haven't used in
any examples but will help you infinitely:
MAN: This is a manual system that
allows you to get more information about a command. For example:
man mv
This will tell you the syntax of the command, the
switches that the command supports, and provide basic examples of using the
command. This is the Dictionary of UNIX and I recommend you use this often
before you get yourself into trouble. Incidentally you can view MAN files in
XCode.
LS: LS is the command for getting a
directory listing. It will show you only the files seen in the Finder. However
you can override this default like so:
ls -la
This will list all the files, showing hidden files as
well as listing their attributes. This is where you will see the R/W/X as
shown in the CHMOD explanation.
RM: This is the delete command in UNIX.
It's basic syntax is:
rm -R ~/Public
You'll see that this command also uses the -R switch. RM
will not remove directories with stuff in them. The recursive delete
switch will override this default. As with most of these commands use this one
with care. It is theoretically possible to do a "rm -R /" which will actually
delete everything on your system. The system will for the most part still work
until you do a reboot and then you're stuffed.
|