Guide To Using Unix On Mac OSX

   Guide to Unix On Mac OSX

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

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

 * curl -o wordpress.tar.gz http://wordpress.org/latest.tar.gz — get the latest WordPress.
 * tar -xzvf wordpress.tar.gz — unpack the downloaded TGZ archive.
 * curl -o wordpress-dashboard-editor.zip http://downloads.wordpress.org/plugin/wordpress-dashboard-editor.zip — download WordPress Dashboard Editor plugin
 * unzip wordpress-dashboard-editor.zip — unpack the downloaded ZIP archive.

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): Select File > Save As from the top menu. .
 * 1) Open the Terminal application located in the   folder.
 * http://wiki.fishcakes.biz/adev/skitch/terminal-00-app-icon-20080826-200444.png
 * 1) Select File > Connect to Server... from the top menu.
 * http://wiki.fishcakes.biz/adev/skitch/terminal-01-file-connect-20080826-191723.png
 * 1) In the Connect to Server window in the Service column, select the Secure Shell SSH folder then click the + (plus) button.
 * http://wiki.fishcakes.biz/adev/skitch/terminal-02-connect-20080826-194859.png
 * 1) Enter the Name or IP Address of your server.
 * http://wiki.fishcakes.biz/adev/skitch/terminal-03-address-20080826-192348.png
 * 1) In the Server column, select the server you just added:
 * http://wiki.fishcakes.biz/adev/skitch/terminal-04-server-20080826-192824.png
 * 1) Enter your Username then click Connect:
 * http://wiki.fishcakes.biz/adev/skitch/terminal-05-username-20080826-195528.png
 * 1) In the new Terminal Window, type your Password (you won't see the characters you type) and press Return (Enter).
 * http://wiki.fishcakes.biz/adev/skitch/terminal-06-login-20080826-193228.png
 * 1) You are now logged in, enter a command. When you have finished, type exit at the command line to close the Terminal window.
 * http://wiki.fishcakes.biz/adev/skitch/terminal-07-loggedin-20080826-193500.png
 * 1) It's also a good idea to save your SSH settings so you can use them again.
 * http://wiki.fishcakes.biz/adev/skitch/terminal-08-file-save-20080826-193823.png
 * 1) Type in a name for your connection (i.e. YourServer SSL Login) and save to the default Terminal folder.
 * http://wiki.fishcakes.biz/adev/skitch/terminal-09-save-as-20080826-194324.png
 * 1) You can now access your SSH settings opening File > Library from the top menu, and selecting the connection you just saved.
 * http://wiki.fishcakes.biz/adev/skitch/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  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, 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  to download and   to upload files. For example, to download the file  to the local computer, type: get text.txt To upload the file  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  prompt type: help

SSH Connection
sudo ssh -l localport:domain:remoteport username@domain Localport should be 2021 on Mac.

See Also:
 * SSH on Mac OS X
 * Learning Mac OSX Terminal
 * Adobe SSH Help

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  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  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  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

means long, and tells  to output additional information such as time, date and permissions info. lists by the last modified time. 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  character indicates the file type,   for a file   for a folder.
 * The next nine characters  give the permissions for user, group, and others.
 * The next lot  tells which user owns the file.
 * Followed by  which group owns the file.
 * Then  is the file size in bytes.
 * Then  is the date and time of last modification.
 * Finally  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: To read, write, execute:
 * u — user owner
 * g — group owner
 * o — others
 * 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.

Other Useful Commands

 * Clearing your DNS cache —

See Also for Mac OSX Unix Commands

 * Apple Developer's Site — official resource.
 * Learning Unix on Mac OSX — tutorial book site (sale no info).
 * Mac OSX Unix Commands — complete list of commands.
 * Glossary of Internet Terms — amazing complete glossary internet terminology.
 * Top 10 OSX Command Line Utilities — from SSH to TOP.
 * www.finkproject.org — open source software for Mac project.
 * SSH on Mac OS X — Arizona State guides.
 * Using Terminal on Mac — excellent tutorial including connecting to SSH server.
 * Unix Crash Course — quick overview of useful commands.
 * About.com Linux Commands — complete reference guide to Linux/Unix commands.