Learning Unix For Mac OS X...

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Part 1

Well, you might ask why ?

Why would I want to learn Unix and type commands into the Terminal, when I have a nice graphical user interface (GUI), Aqua !

Well I will show you a few tips that may or may not come in handy !

First you need to open 'Terminal' it's in your Applications/Utilities Folder...

Drag it down to the dock so that it's readily accessible !

One thing to remember about using Unix...it is very powerful !

So as always make sure you are well backed up 'before' starting to tinker...

You might not want to become the next Unix Guru, but learning just a few 'bit's can certainly, help you out if your Mac starts misbehaving ! Or if you need to do something and you can't find a way in the normal 'Aqua' interface !

The Terminal...
 

Attachments

  • Terminal001.jpg
    Terminal001.jpg
    19.4 KB · Views: 417
  • Finder006.jpg
    Finder006.jpg
    17.7 KB · Views: 428

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
First off...

Your version will look similar to this...

Obviously there will be differences to what's on your hard drive and what's on mine.

All commands in the following posts will be written in bold...you need to type these in and then press return ! (When using UNIX folders are known as directories !)

To start with. A few common commands that we will use a lot !


pwd

this displays the current working directory...in Apple GUI terms which folder are you currently working in.


clear

clears the Terminal screen.


ls

lists files and/or directories, examples to follow.


cd directory name

cd will change you to that working directory, examples to follow.


man ls

man command name... This allows you to access the built in documentation for different UNIX commands ie man ls man top etc if there is no man pages for the relevant command the terminal will let you know, examples to follow.


cp original_filename copied_filename

cp copies a file or files from one place to another, examples to follow.


mv original_filename copied_filename

mv moves a file or files from one place to another, the original file is deleted, examples to follow.


rm filename or directory name

removes a file, or files, or directories. (Very powerful), examples to follow !


I will post examples for each one below. Each one of the above commands has numerous 'switches' or variations, these we will also explain !
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
pwd

this displays the current working directory...in Apple GUI terms which folder are you currently working in.

The pictures below show pwd being entered. Depending on how you have Terminal setup, you can quite easily 'forget' what directory (folder) you are in.

If you look at the 'prompt' you should see though that this tells you what directory you are currently in !

The ~ (tilde) in picture 1 tells me that I am in my 'home' directory...my username is 'computer'. (Big Mac is the name of my internal Hard drive)

So if you imagine this in the normal GUI, I am in the folder as below:

Big Mac-->Users-->computer

This is my 'Home' folder !

In the last picture you can see that I have used the 'cd' command to move into the applications directory (folder)...
 

Attachments

  • Terminal001.jpg
    Terminal001.jpg
    18.6 KB · Views: 405
  • Finder001.jpg
    Finder001.jpg
    84.5 KB · Views: 402
  • Terminal002.jpg
    Terminal002.jpg
    19 KB · Views: 391
  • Terminal003.jpg
    Terminal003.jpg
    22.3 KB · Views: 417
  • Terminal004.jpg
    Terminal004.jpg
    28.2 KB · Views: 421

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
pwd

to find out more about the pwd command type

man pwd

and press return.

There are only two 'switches' or 'options' for pwd in OS X Tiger -P and -L

Man page below...
 

Attachments

  • Terminal005.jpg
    Terminal005.jpg
    67.7 KB · Views: 396

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
clear

clears the Terminal screen.

Thats it, it just cleans/clears the terminal screen, so that you can see what you are doing...

again

man clear

tells you about it ! Not that there's much to tell !
 

Attachments

  • Terminal006.jpg
    Terminal006.jpg
    34.1 KB · Views: 432

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
ls

lists files and/or directories.

This command you will use all the time, below are some examples.

ls is often used with additional 'options'

ie


ls -l (that's a lowercase L)

This changes the normal output from ls to the 'long' format !

In picture two you can see what I mean...

When using UNIX commands like ls you can add one or more options to it,ie:

ls -l -a

The two options above are -l (lowercase L again) and -a

The -a will show all files, including all the 'hidden' system files (have a look at pic 3 and 4)

ls -a can also be used on it's own. (pic 5)

The -a option is one that we will use a lot !
 

Attachments

  • Terminal007.jpg
    Terminal007.jpg
    30.4 KB · Views: 395
  • Terminal008.jpg
    Terminal008.jpg
    117.4 KB · Views: 374
  • Terminal009.jpg
    Terminal009.jpg
    144.8 KB · Views: 409
  • Terminal010.jpg
    Terminal010.jpg
    40 KB · Views: 436

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
ls

as we said before you can use one or more options for most Unix commands.

Some will work as ls -la however some will require you to type out the command in full ls -l -a they both accomplish the same thing. There is no hard and fast rule, but the ls -l -a way of entering multiple 'options' should always work.

man ls will give you the documentation for the ls command

ls -a is the first bit of Unix that shows you how powerful it can be.

The standard Mac GUI will not allow you to see invisible files/folders on your Mac yet by typing ls -a you can see all the invisible files/folders within that directory.

Have a look at pic 1, this is in the Mac GUI, on my Mac it would appear that there are only 7 folders on the top level of my Mac and no files...

Then have a look at pic 2, as you can see there are quite a few hidden files and folders (directories).
 

Attachments

  • Finder002.jpg
    Finder002.jpg
    55.4 KB · Views: 416
  • Terminal011.jpg
    Terminal011.jpg
    39.7 KB · Views: 386

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
ls -a

What the previous command didn't tell us though was which of those are files and which are directories !

So if we do a ls -al (lowercase L) then this gives us the long list of all the files and folders within the working directory...

from this list we can see some characters on the left like this:

Code:
drwxrwxr-t   31 root      admin     1156 Sep  1 13:43 .
drwxrwxr-t   31 root      admin     1156 Sep  1 13:43 ..
-rw-rw-r--    1 computer  admin    15364 Sep  1 17:23 .DS_Store
drw-------    7 root      admin      238 Jul 19 22:47 .Spotlight-V100
d-wx-wx-wt    3 root      admin      102 Aug 18 21:51 .Trashes
-rw-------    1 root      wheel   196608 Aug 22 15:46 .hotfiles.btree
dr-xr-xr-x    2 root      wheel       96 Aug 31 20:11 .vol
drwxrwxr-x   70 root      admin     2380 Aug 30 23:54 Applications


The "drwxrwxr-t " bits are the ones that we are interested in !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

IT tech learning Mac 7

Top