aspose file tools*
The moose likes Mac OS and the fly likes Unix Tutorials Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Unix Tutorials" Watch "Unix Tutorials" New topic
Author

Unix Tutorials

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

As a new Mac user, I feel that I need a crash introductory course in Unix. Now that my machine is configured for Java 5.0, I'm probably over the worst of it. Moving forward, I don't anticipate using much more than "cd" along with some Java commands, but I still want to learn more so I'm not such a Mac "greenhorn."

I've found the following tutorials. Does anyone have other advice?

http://www.isu.edu/departments/comcom/unix/workshop/unixindex.html

http://www.ee.surrey.ac.uk/Teaching/Unix/

http://www.math.utah.edu/lab/unix/unix-tutorial.html


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
The first thing to do is realise that Unix is traditionally a command line driven operating system. As such the command line is extremely powerful.

When I first started using Unix we had no windowing system, just a command interface.

The best way to learn is to pretend that you dont have a windowing system and do as much as possible from the command line... Creating, deleting, moving, editing files and directories would be a good place to start.

Learn where everything is on your system. For example, where are user accounts created? Where are the applications stored? Explore the OS and learn your way around.

The man command is your best friend - On all Unix systems you can generally do type "man <command>" - for example man ls - to get instructions on a command... the man pages show all the information you need for each command including the hundreds of options Unix commands take (for example, look at man ls and see how many options you can pass to it). If you are not sure what command to type for a task use the -k flag which will search for the given keyword.

After you have the basics I would recommend looking at shell scripting which is where real control of a Unix OS comes from - by default you are using bash on Mac OS X so do man bash and look at some of the syntax examples in the man pages - as a programmer it will all be familiar - I would think the only thing you need to learn here is the syntax and how IO works.

Next up is permissions. Learn how to change permissions and ownership on files. Learn the binary notation for setting permissions - e.g. chmod 700 etc.

Once you have the Unix commands down and can get simple shell scripts up and running the next stage is to look at your environment. Learn about the contents of .profile. .bash_profile, .bashrc etc. You can get answers about these on the web. By being able to configure these files you can customise your command line environment - for example I set JAVA_HOME, PATH and CLASSPATH in my profile files - I also alias the command 'ls -l' to ll so I can just type ll to get a long file lising.

Finally - and the most difficult - learn vi. vi is the command line editor for Unix. It is amazingly powerful and enables very fast editing of files - it has fantastic regex support - it does take a leap of faith because editing files is very strange, for example, you press i before inserting text - 0 to get the start of the page and cursor movements are controlled with hjkl and not the cursor pad. Once you have mastered vi then you will not use anything else to edit text files - trust me :-)

WARNING: The Unix command line interface is VERY powerful - there are no recycle bins / trash cans / undo's etc on Unix so be very careful using commands like rm (especially with the -r flag and even more if you append a / to it . Your default account on Mac OS X will stop you killing much outside of your own environment but as you know the sudo command lets you do anything you like - always check your current location using the pwd command before executing any move or delete commands.

With any luck you will have the same experience as I did when I started on Solaris. Once you use Unix from the command line and realise how perful it is it is very difficult to go back to using a point-and-click restrictive environment like WIndows.

Happy tapping.


ph34r my 133t j4v4 h4><0r1ng sk177z
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

If you really really want to get into learning how to use Unix to its full capability (not entirely necessary in order to use OS X as a development environment, but a very good skill set to have under your belt), then I think Rick's suggestions are good.

The one caveat I have is with:

Finally - and the most difficult - learn vi.


I've been using Unix-es of various flavors for over 2 decades and I've never come to terms with vi. If you want to use a terminal-window editor on OS X (I rarely do -- I prefer BBEdit which can easily be launched from the command line or from the GUI) I'd recommend pico. I find it much less frustrating than vi.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Originally posted by Bear Bibeault:
I'd recommend pico. I find it much less frustrating than vi.


Looks quite good - I haven't seen that program before.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

I also just came across this yet-to-be-published book.

Don't know personally if it will be any good or not. You may want to research the author.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

And lastly, the O'Reilly Mac DevCenter is a good place to check out now and again.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
I've recently considered looking at this book:
The Mac OS X Command Line: Unix Under the Hood

These 2 links are in my bookmarks:
OS X's BSD/unix command-line
Advanced Bash-Scripting Guide
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Wow! Thanks for the suggestions!

I'm impressed by the apparent enthusiasm for Unix here. Coming from a Windows background, I didn't expect much response on this topic.

(Hey... I just learned how to "right-click" by using ctrl+click. )
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
pico less frustrating than vi?!

Bear, you're a nice guy, but respectfully, that opinion is perverse. vi is hard to learn, but it has enough power to be a mainstay programmer's editor; pico runs out of steam on me very, very quickly. i think i'd use Emacs before pico, and i have serious disagreements with Emacs...

that said, noone needs to lack for a text editor on any Unix system. you don't necessarily need a text-mode one, either; these days, graphical applications are becoming quite acceptable even for such basic needs. use whatever text editor works best for you... unless it's pico.

for learning unix in general, the "man" command is indeed your friend. there's an old joke about telling a newbie to do "man /usr/bin/*" and reading it all, but frankly it's in questionable taste. if you don't know quite what command to read the man page for, most Unix systems have an "apropos" (also known as "man -k") command that'll search the man page database for a word and output a list of all the man pages that seem to concern it. it's only moderately useful, though, because if development libraries (a C compiler and library headers) are installed, there tend to be a profusion of man pages on any conceivable subject that only a systems programmer would care about. still, it's better than nothing.

another tip is simply to take an afternoon and go digging around in the directory tree. see what directories there are in those cryptic-looking locations like /usr, /etc, and so on, and what files are in them. learn the more useful switches to give ls in order to find these files, and maybe learn piping and redirection to page through the file lists with more and less. when you find a file that looks particularly interesting, use the man pages to try and find out what it's for. or just read it, see if it makes enough sense for you to figure it out from context.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

but it has enough power to be a mainstay programmer's editor;


Perhaps, but I'm not talking about using it as a "programmer's editor", but as something quick and easy to use when you need to make a change to a text file.

vi fails miserably when measured against "quick and easy".

Now if it's "power" you are after, I'd take emacs over vi, but as you point out using a Terminal-based editor for day to day editing isn't realistic or necessary.

I have BBEdit and what's great about it (besides the usual things), is it has an easy command-line launcher so that launching it while working on the command line doesn't entail leaving the Terminal window and finding the Finder and double-clicking the icon and ...

But BBEdit is far from free, so that's why I mentioned pico as a Terminal-based editor that you can successfully start using in under a minute.
[ May 04, 2005: Message edited by: Bear Bibeault ]
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Only slightly off topic...

Does anyone know why the etc directory is called etc? Does it stand for something? This came up in the office a few days ago.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
I have BBEdit and what's great about it (besides the usual things), is it has an easy command-line launcher so that launching it while working on the command line doesn't entail leaving the Terminal window and finding the Finder and double-clicking the icon and ...

I thought you could open *any* app from the Terminal with

open -a ApplicationName

or a specific file with

open -a ApplicationName PathToFile


SubEthaEdit is my favorite editor - it's free for non-commercial use, only $35 for a commercial license.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

open -a ApplicationName


Yes, but BBEdit installs a specific 'bbedit' command that make it really easy. I like easy.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

etc


I always thought it was short for et cetera.
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
i always thought it was short for "etcetera", also. it probably, at some early point in prehistory, held assorted system files that didn't well fit anywhere else, but of course the semantics and usage have long since shifted.

i do know that /usr was named so because, at one point, it held all the users' home directories. those go under /home nowadays, of course.
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
etc = essential text configuration (this is where configuration files are)
usr = unix system resources (this is where the OS is)
bin = binary (this is where program exceutables are)
lin = library (this is where OS libraries are)
var = variable (used for variable file length storage - e.g. logs
tmp = temp - this is your RAM

Hope that helps
[ May 05, 2005: Message edited by: Rick Beaver ]
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Cool! Thanks Rick.
Ben Poole
Ranch Hand

Joined: Jul 17, 2003
Posts: 33
Another tip for learning UNIX: never EVER start talking about text editors... LOL!

vi isn't too bad, but I often have to have my quick reference to hand. And if it all gets too much, SubEthaEdit comes with an optional CLI invocation, "see" which works very well
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
vi has a very steep initial learning curve, but it grows on you. its single-letter commands tend to find their way into your automatic reflexes; after a while of using it, you may find yourself doing editing actions without any clear idea of what keys you are hitting to perform them, just that your text gets edited the way you want it.

the modern-day Unix directory tree layout is somewhat chaotic, having mostly just accreted with little real design. there are few standards to it, and i doubt Mac OS X really follows any of them, except possibly whatever standards are made in-house at Apple. but, in case you ever look at other unices, the Linux Filesystem Hierarchy Standard has had some amount of influence; it's reasonably well followed in the Linux world. it won't, perhaps unfortunately, give you much historical perspective on how things came to be the way they are, but at least it'll let you know how many Unix-like OSes try to arrange themselves. i don't know how well, if at all, it applies to the Mac OS X directory layout, however.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Rick Beaver:
... Hope that helps

Definitely!
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6

Yes, but BBEdit installs a specific 'bbedit' command that make it really easy. I like easy.


And here I thought you command line guys really like typing.

Just discovered that SubEthaEdit also has a command line tool that gives you a 'see' command. Nice. Less typing too.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Came across another article on using the OS X shell, thought I'd drop it here:

bash on Mac OS X from O'Reilly's macdevcenter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unix Tutorials