< hello

 

resources

 

 

 

 
 

 

 
 

 

Unix Basics for OSX Users

Note: This super-basic introduction is geared towards OSX users. There are I'm sure dozens of bettter tutorials out there, so please look; but, hopefully this will help get you started.

 

First off, beware that some of these commands might not work correctly if you're not using the 'Bash' shell. You'll know your using 'Bash' if when you open Terminal the window's title-bar says something like "Terminal-bash-80x36". If it doesn't say Bash in there, use your mac's System-Help to find a file that explains 'changing to a different shell'.

 

 

...

 

 

Unix is a beautiful thing. I find Unix extremely poetic and interesting, and it really seems to bring out the dork in me. Learning just a little bit about using Unix (also known as programming at the command-line) can really really help you better understand how your Mac or Linux machine works, about what's going on under-the-hood. Basically, understand this: whenever you click on an icon, move a file somewhere, open an application, delete a file, upload a file to your website, etc, you are secretly using Unix. The GUI of the Finder and the other programs you use just hide the nitty-gritty of command-line from you by allowing you to click a button or two that automate those tasks. By learning more about Unix you can potentially gain more low-level control of your machine; you'll also be able to use various pieces of software that can only be installed and accessed from the command-line.

 

 

...

 

 

Here's how to get started: Go to your Utilities folder and open the Terminal application. You'll be presented with your user name and a prompt. Magical, right? Well at this point you have to start learning some commands, but you really don't need to know that many to get around and do basic stuff.

 

Type in the following:

cd /Applications
ls

 

You just did two things. cd /Applications means 'change the current directory to the Applications folder'; ls simply means 'list the files in the current directory'. After hitting return after that last line, Terminal should have spit out the name of every file and folder in the current directory. At this point you can then manipulate, move, delete or open any of the files in this directory, and you can use the ls command to help you see what you have to work with. Let's say that you want to create a new folder where you can store all of your wonderful new development programs. Type:

 

mkdir Dev_Apps
ls

 

 

You just made a folder named Dev_Apps. If you want, confirm that it's there by going to the Finder and opening the physical Applications folder. Now let's pretend we hate programming and want to delete the folder we just made:

 

rmdir Dev_Apps
ls

 

 

...

 

 

So far we've been searching for things relative to the directory we're currently sitting in. For instance, we can move around simply by typing a cd command with a path relative to our current position, which means we don't have to write out the path from the very, very bottom, all the way up to where you want to go. So let's go to the Utilities folder from here:

 

cd /Applications
cd Utilities

 

We could've also typed this instead:

 

cd /Applications/Utilities

 

Notice for a moment the forward-slash (/). The forward slash represents the lowest directory level, which I think will always be your hard drive, and when you decide to type a path starting from this lowest level, you're writing what's called an absolute path. Everything is built up from there and there's no question what folder or file you meant to access. When writing paths that are relative to where you're currently sitting, you won't use a forward-slash, you'll just start with the actual folder-name like I did with the Utilities folder. Try navigating your system some using both ways. Also, in order to 'back-up' one level, try typing cd .. , or cd ../.. for two levels.

 

 

...

 

 

Can't remember what files or folders are in your current directory? Here's a tip for the forgetful. Start typing cd /, but then before typing anything else just hit the TAB button twice. Terminal will then print out all of the files in that directory and then return you to exactly where you left off typing. So now you see that there's a folder called 'Applications'. Now instead of typing the whole path, just start typing the first few letters, 'Appli', and then hit TAB once. Terminal should fill in the rest of the file or folder-name for you. If you type in a couple letters that are shared by two or more files or folders, nothing will happen the first time you hit TAB; but the second time you hit it, Terminal will print out all of the files and folders that you still have to choose from and will then return you to your command-line so that you can finish out your pathname.

 

Note that file and folder names with spaces or special characters have to use the backward slash (\), known as the escape character. For instance, to go to the folder 'Apps Dev (new)', you have to type:

 

cd Apps\ Dev\ \(new\)

 

That's when the TAB trick really comes in handy...

 

 

...

 

 

One way to learn more about Unix commands is to use your computer's built-in Unix manual. To open the manual you'll use the man command followed by a command you'd like to learn about. For instance:

 

man mkdir

 

Try this for several different commands like cd, rmdir, cp, rm, open, ftp, sftp, scp, date and others. (To get out of the manual, simply hit the 'q' key to effectively 'quit' and return to where you left off.) To find out what other commands are available you can simply type in help to get a nice phat list of them. In addition, you can type help and then the name of a command to get a super-brief description of it, compared to the more lengthly manual entry.

 

 

...

 

 

This is just a super basic look at how Unix works. There's definitely more than this, but not really that much more is needed for getting around and doing the basics. There's tons more resources online that go through all of the different commands, their flags, etc, in much better detail than I have provided here. One decent-looking intro that I just found is located at WebMonkey.com, but there should be plenty of other more comprehensive ones all over the place...

 

If you're really into books and you're a beginner, I recommend checking out the O'Reilly book Learning Unix for Mac OSX Panther for a decent tutorial on Unix commands. I still find it to be pretty helpful sometimes, though not all the time.

 

.  .  .

 

 

PLEASE NOTE: For a number of personal reasons I am currently unable to support this page and am unable to respond to any further questions, requests, demands, etc posted here. I sincerely apologize for this. The material above is simply presented as archival material (some of it incomplete) of a project that I am not actively involved with anymore, and it will probably not be updated any further. You are free to use it in whatever non-commercial ways you wish (see the CreativeCommons license below). In addition, feel free to use the comments-section below to post ideas, solutions, or to ask questions, but with the understanding that any queries will have to be answered by the community at large - not by me. Thanks for understanding.

 

POST A COMMENT

   
  To post, please enter the following code:      
    Author:    

 

 

this page has been viewed 507 timeshttp://plus1plus1plus.org/Resources/unix
last updated 21 January 2010, at 04:23 PM PST

Creative Commons License

built with PmWiki
. Edit