Guide To Using Unix On Mac OSX
From Fishcakes Wiki
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
- 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):
- Open the Terminal application located in the
Applications > Utilitiesfolder. -
- Select File > Connect to Server... from the top menu.
-
- In the Connect to Server window in the Service column, select the Secure Shell SSH folder then click the + (plus) button.
-
- Enter the Name or IP Address of your server.
-
- In the Server column, select the server you just added:
-
- Enter your Username then click Connect:
-
- In the new Terminal Window, type your Password (you won't see the characters you type) and press Return (Enter).
-
- You are now logged in, enter a command. When you have finished, type exit at the command line to close the Terminal window.
-
- 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. -
- 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. -
- You can now access your SSH settings opening File > Library from the top menu, and selecting the connection you just saved.
-
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
dcharacter indicates the file type,-for a filedfor a folder. - The next nine characters
rwxr-xr-xgive the permissions for user, group, and others. - The next lot
dansalmotells which user owns the file. - Followed by
staffwhich group owns the file. - Then
2346is the file size in bytes. - Then
Jul 18 09:39is the date and time of last modification. - Finally
Desktopis 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:
- the next part of the path will be automatically filled in for you, if what you have typed so far is unambiguous.
- a list of possibilities is displayed if it is ambiguous.
- 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
- 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.
Macintosh Links
Official Apple Resources
- apple.com — Apple's UK website.
- discussions.apple.com — Apple Discussions community forums.
- selfsolve.apple.com — use Apple's Online Service Assistant to enter a serial number and get warranty info.
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
- radmind Mac OSX Manual — exhaustive reference guide.
- tuaw.com Mac Blog — excellent guides to getting the most out of your Mac. Geared towards Mac tech professionals.
- macsc.jthree.co.uk — free video tutorials to Mac OSX users, both experienced and switchers.
- russellbrown.com Tech Tips — great site full of video tutorials by Russell Brown.
- macdevcenter.com — Web Apps with Tiger — tutorial on installing a web server for OSX.
- ksdd.com Mac OSX Server — very good explanation of how the OSX web server works.
- macinstruct.com — Mac Instruct tutorials on a range of Mac related topics.

