Guide To Using Unix On Mac OSX

From Fishcakes Wiki

Jump to: navigation, search
  • Icon_Mac_20px.png Macintosh
  • Keyboard Shortcuts
    Apple Mac OSX Keyboard Shortcuts to help you work faster and better!
  • Mac Hardware
    Notes about specific Apple Macintosh computers.
  • Mac Research
    Research into various solutions for backup, email, archiving and such.
  • Mac Software
    A list of Mac software with links to support pages.
  • Unix on Mac
    How to use command line access to control your Mac.
Edit Menu

Image:Icon_Mac_40px.png Guide to Unix On Mac OSX

Notes about how to do specific things using the OSX Terminal application to access Unix.


Contents

FTP & SSH Quick Guide

Some useful Shell commands for Unix/Linux:

  • tar zxvf filenamehere.tar.gz — unpack the archive filenamehere.tar.gz.
  • tar -cvf target_file.tar -c source_file — create archive to target from source.
  • mv new_file old_file — move to new filename from old filename (also rename).
  • cp new_file old_file — copy to new filename from old filename.
  • pwd — show current directory location.
  • rm -r foldername — remove recursive target foldername (deletes folder, subfolders and all files.

WordPress Shell Commands

See also United Support: Basic SSH — list of useful commands

Connecting to a Remote Server

Follow the steps below to connect remotely using Mac Terminal (OSX 10.4):

  1. Open the Terminal application located in the Applications > Utilities folder.
    terminal-00-app-icon-20080826-200444.png
  2. Select File > Connect to Server... from the top menu.
    terminal-01-file-connect-20080826-191723.png
  3. In the Connect to Server window in the Service column, select the Secure Shell SSH folder then click the + (plus) button.
    terminal-02-connect-20080826-194859.png
  4. Enter the Name or IP Address of your server.
    terminal-03-address-20080826-192348.png
  5. In the Server column, select the server you just added:
    terminal-04-server-20080826-192824.png
  6. Enter your Username then click Connect:
    terminal-05-username-20080826-195528.png
  7. In the new Terminal Window, type your Password (you won't see the characters you type) and press Return (Enter).
    terminal-06-login-20080826-193228.png
  8. You are now logged in, enter a command. When you have finished, type exit at the command line to close the Terminal window.
    terminal-07-loggedin-20080826-193500.png
  9. It's also a good idea to save your SSH settings so you can use them again.
    Select File > Save As from the top menu.
    terminal-08-file-save-20080826-193823.png
  10. Type in a name for your connection (i.e. YourServer SSL Login) and save to the default Terminal folder.
    Users/~yourusername~/Library/Application Support/Terminal.
    terminal-09-save-as-20080826-194324.png
  11. You can now access your SSH settings opening File > Library from the top menu, and selecting the connection you just saved.
    terminal-10-library-20080826-194429.png

FTP & SSH via the Terminal

How to use the Terminal for FTP connections. To access the Terminal FTP Manual, type man ftp at the command prompt. See docs.info.apple.com Mac OS X Server: What Is FTP?

Connecting to the Server

At the command prompt, type ftp [hostname], where [hostname] is name of the remote computer, and press return:

ftp fishcakesmedia.com

When prompted enter your username and password and if successful the prompt will change to:

ftp>_

The most commonly used commands are get to download and put to upload files. For example, to download the file text.txt to the local computer, type:

get text.txt

To upload the file text.txt to the remote computer, type:

put text.txt

Most standard Unix-compatible commands can be used in FTP. To get a list of all the commands FTP accepts, at the ftp> prompt type:

help

SSH Connection

sudo ssh -l localport:domain:remoteport username@domain

Localport should be 2021 on Mac.

See Also:

Guide to Using Unix

Notes from an online tutorial to using Unix on Mac OSX located at Mac OS X Unix Tutorial.

Part 1 - Using the Terminal Application

Open the Terminal application. You are automatically logged in and will see the welcome message:

Last login: Wed Jul 18 08:54:39 on console
Welcome to Darwin!
[77-101-72-136:~] dansalmo%

The bit between the brackets is your machine name (IP) followed by short username.

The 'ls' command

Now type (don't type the %):

% pwd

Hit return and then use the list directories command. Now type:

% ls

This lists the contents of your home directory. Now type:

% ls /Users

This gives a list of users on the computer. Now type:

% ls /Users/replace-with-your-user-name

This lists the contents of the replace-with-your-user-name directory. Now type:

% ls /

This lists the contents of your system disc. You will notice there are more files and directories at / than the Finder shows - it is hiding stuff from you! And finally type:

% ls Documents

This lists the contents of the Documents folder. If a path begins with / then it is absolute, i.e. Unix will start from the root of the file system (your system disc) and follow the path you have given to find the file or directory at the end of the path. If the path does not start with a / then it is relative and Unix will start its search from your current working directory.

The 'cd' command

Now type:

% cd /Users

The cd command changes your current working directory and can be either absolute or relative. Your current working directory is now set to the Users directory just above your home directory. Notice that the directory has been added to the prompt which now reads:

[77-101-72-136:/Users] dansalmo% 

To get back to your home directory, type either of:

% cd /Users/your-home
% cd ~
% cd
% cd -

The ~ or tilde character is shorthand for your home directory. Typing just cd will also take you back to your home directory. The - dash will take you back where you came from.

Advanced 'ls' commands

To get more detailed information about any item, type:

% ls -l
% ls -t
% ls -lt

-l means long, and tells ls to output additional information such as time, date and permissions info. -t lists by the last modified time. -lt outputs long by time. An example of the information output:

drwxr-xr-x   69 dansalmo  staff   2346 Jul 18 09:39 Desktop
-rw-r--r--    1 dansalmo  admin      0 Jul 17 16:59 WebServer
  • The initial d character indicates the file type, - for a file d for a folder.
  • The next nine characters rwxr-xr-x give the permissions for user, group, and others.
  • The next lot dansalmo tells which user owns the file.
  • Followed by staff which group owns the file.
  • Then 2346 is the file size in bytes.
  • Then Jul 18 09:39 is the date and time of last modification.
  • Finally Desktop is the filename itself.

Auto Completion

By hitting the tab key as you are partway through typing a pathname or file name, one of three things will happen:

  1. the next part of the path will be automatically filled in for you, if what you have typed so far is unambiguous.
  2. a list of possibilities is displayed if it is ambiguous.
  3. nothing, if it does not represent a path that exists.

Try hitting the tab when typing:

% ls /U

Auto completion also works when you are partway through typing a command.

Logout

When you wish to finish working at the command line close the Terminal window by typing:

% logout

That's it.


The 'chmod' Command

Use chmod to change file permissions. For users, groups, others:

  • u — user owner
  • g — group owner
  • o — others

To read, write, execute:

  • r — read permission
  • w — write permission
  • x — execute permission.

To set permissions to use:

chmod u=rwx file-name            --> read, write, and execute (rwx) for user owner (u) 
chmod g=rx file-name             --> read and execute (rx) for the group owner (g)
chmod o=r file-name              --> read (r) for others (o)
chmod u=rwx,g=rx,o=r file-name   --> set all at once by separating permissions by commas.

Add or remove permissions by replacing = with + to add, or a - sign to remove:

chmod o-r file-name              --> away read permission for others
chmod g+w file-name              --> add write permission for group

Part 2 - Playing With Files (page 1 of 2)

Tools needed to create, copy, move, rename, delete, and view files.

dot Files

To view all files, including hidden system files, type:

% ls -a

A hidden file is no different to a normal file, other than its name beginning with dot. A hidden file is often used to hold configuration information that does not need to be viewed or changed regularly. Hiding avoids visual clutter in the directory listing.

You can create your own hidden files:

% touch .hidden
% touch not-hidden
% ls
% ls -a

Touch is an easy way to create a new (empty) file. 'ls' will list just 'not-hidden' while 'ls -a' will list both.

Tutorial not yet completed YOU ARE HERE.


See Also for Mac OSX Unix Commands

Image:Icon Resources 20px.png Macintosh Links

Official Apple Resources

Unofficial Mac Resources

  • applelinks.com — Apple Links Macintosh news, reviews and how-to guides.
  • iusethis.com OSX — I Use This digg style site for sharing info on the best applications for your computer.
  • macblogger.net — Mac Blogger rumours and reviews of what's coming out from Apple.
  • maczealots.com — Mac Zealots community site with excellent Articles, Reviews, Tutorials and User Requests about Mac hardware and software.
  • versiontracker.com — download the latest Mac OSX software.

Mac User Guides & Tutorials


Personal tools