PDA

View Full Version : Definitive UNIX Primer for the Wannabe Hardcore...?




darkgoob
May 16, 2012, 10:06 AM
What is a very good UNIX primer for really learning shell scripting and some of the most powerful and useful command line tools that come standard with OS X?

I want to learn shell scripting, the differences between different kinds of shells, what the various folders in the UNIX directory structure are supposed to be for, what the various concepts upon which UNIX is based are, how to properly use XWindows, etc. etc.

So, I want a fairly advanced and comprehensive primer written for someone who has an advanced knowledge of computers but no UNIX knowledge.

My problem is that man-pages are written in a way that assumes you already know a lot of stuff. They just list out all the available commands in alphabetical order with basic descriptions of what they do, but they usually do not tell you which of those commands are more commonly used than others nor do they go into much detail about why you would want to use them. They usually don't give even a single example to show you what a properly-formatted command would look like.

What I would like to see in such a primer would be, for each UNIX command, several real-world examples of its usage on the command line and/or in a shell script, with an explanation of why it was used that way and how it could be tweaked to other purposes. (I realize it probably wouldn't have every UNIX command available in there, but you know, as many as possible would be nice.)

I would also like this primer to talk about how to download and install UNIX software onto Mac OS X. I realize that things like FINK are out there, but sometimes the FINK version is outdated and you want to roll your own. This can be complicated, but I would like to understand exactly what kinds of things to look for to modify an installation of UNIX software to run on OS X.

Finally the primer should describe the differences between the UNIX implementations on the various versions of OS X, and what the optional UNIX installs are for each version (such as Apple's developer tools, extra things that are only in OS X server, extra things that are only present if the user selected the optional UNIX stuff when installing Tiger, etc.).

Does such a book or online primer exist? If not what is the closest thing? What have you all found useful?

I am tired of having to google everything and dig around through forums where someone asks a question, then there are 99 garbage posts and one useful tidbit. I'm tired of reading various general UNIX guides here and there that are not cohesive and either talk to you like you're already a UNIX expert, or talk to you like a beginner leaving out the "confusing details."

My background:

I am an iOS developer. I can deal with C and Objective C, along with a smattering of Java and other stuff. I have been using Macs since 1984. I have done a little bit with VI, VIM. I know what a $PATH is. I know the basic UNIX commands, and realize that there are different shells. In the past I have used EMACS to compile Java code for an XWindows project. These days I do all my development in Xcode, but I want to do some server programming with PHP using my Mac as a testing ground, and also some C#/mono development, and I'm finding that my UNIX knowledge is weak.

Thanks

-=DG=-



thundersteele
May 16, 2012, 10:24 AM
1. The documentation for most command line tools can be accessed by typing "man PROGRAMNAME" in the terminal
2. Read the documentation from (1)
3. Google or scroll to the end of the man pages to find examples of program use

For a "how do I..." type of problem, the above (+google) will usually help.

For a deeper understanding of UNIX, I would install Linux (or BSD?) on some machine (maybe a virtual machine). Try to find a distribution that is not fully automated, e.g. like gentoo linux, or "linux from scratch" (lfs) for the hardcore experience. That should teach you a lot how unix/linux systems are structured.

chown33
May 16, 2012, 11:33 AM
Shell Scripting Primer (http://developer.apple.com/library/mac/#documentation/OpenSource/Conceptual/ShellScripting/)

Bash Guide for Beginners (http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html)


Several of your stated goals are in conflict. For example, take this statement:
So, I want a fairly advanced and comprehensive primer written for someone who has an advanced knowledge of computers but no UNIX knowledge.

There's no such thing as a primer that is advanced and comprehensive. If it's advanced, it's no longer a primer (a primer being a book on elementary principles). It's also impossible for a primer to be comprehensive, since then it would be a comprehensive (encyclopedic) reference, which is also no longer a primer.

Some of your questions don't have anything to do with shells. For example, the directory structure. See these:
http://en.wikipedia.org/wiki/Unix_directory_structure
http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard


Finally, there is a difference between Linux and Posix. Mac OS X is Posix compliant; Linux is not (and doesn't want to be). So some of what you see written about "Unix" is actually Linux specific. You should learn what Posix is, so you know what to look for when reading things:
http://en.wikipedia.org/wiki/POSIX
http://pubs.opengroup.org/onlinepubs/009695399/

subsonix
May 17, 2012, 10:02 AM
A very good, and classic primer is "The UNIX programing environment" by Brian Kernighan and Rob Pike. These guys was involved with creating the OS at AT&T. It's not a thick book but with a surprising amount of information, with very good examples, that you actually can learn from. The book make many references to the unix manual, which used to be available in print, today you have it on-line and in your terminal instead with the man command.

Another book you should get is "The art of UNIX programming" with a philosophical background that connect lot's of concepts and central ideas behind the architecture and design. This helps you be a good citizen, and design programs that fits into the same model, it gives examples of making a good file format design, protocols and so on, with links to very good papers on the matter for example. Some part of this book is religion though, so you might want to skip some parts. :)

For the UNIX syscall interfaces there is another classic, "Advanced programming in the UNIX environment", which is a reference book with included examples and explanations. There is another book on UNIX networking (also from Adison Wesley) that I have not read.

For an overlap on OS X specific topics beyond posix there's "Advanced OS X programming", which covers some of the parts in the above book.

http://www.amazon.com/Programming-Environment-Prentice-Hall-Software-Series/dp/013937681X/ref=sr_1_1?ie=UTF8&qid=1337266514&sr=8-1
http://www.amazon.com/The-UNIX-Programming-Eric-Raymond/dp/0131429019/ref=sr_1_1?s=books&ie=UTF8&qid=1337266548&sr=1-1
http://www.amazon.com/Advanced-Programming-UNIX-Environment-Edition/dp/0201433079/ref=sr_1_2?s=books&ie=UTF8&qid=1337266566&sr=1-2
http://www.amazon.com/Advanced-Mac-OS-Programming-Guides/dp/0321706250/ref=sr_1_2?s=books&ie=UTF8&qid=1337266590&sr=1-2

If you get these book you should have a solid grounding, and know where too look if you're stuck.

I like IBM developer works for online resources, they have tutorials on bash, awk, sed and so on.

throAU
May 18, 2012, 01:30 AM
Download FreeBSD and get it working in a VM with video and sound. Use it as a play pen you can break and try new stuff on.

You'll want virtualbox
http://www.virtualbox.org

and FreeBSD

http://www.freebsd.org

Enjoy.

WebMongol
May 18, 2012, 03:21 AM
"The UNIX programing environment" by Brian Kernighan and Rob Pike is a classic but it was published in 1984. A lot of things changed in last 28 year. Combination of this book and "C Programming Language" by Brian Kernighan and Dennis Ritchie is the best introduction to UNIX but it's not for everybody.

Second book to consider is "UNIX for Programmers and Users" by Graham Glass (Author), King Ables. This book is oriented to developers and goes beyond basic command and shell. But the last edition was published in 2003.

UNIX is name of family of operating systems that are rather different. You many want to book specific for your OS (Mac OS X, Ubuntu Linux or Solaris). Mark Sobell has written a number of OS specific books. There are a number of OS X specific books, like "Mac OS X for Unix Geeks".

If you are interested in sysadmin tasks "UNIX and Linux System Administration Handbook" by Evi Nemeth, etc is the best bet.
As you can see there is no single primer book to "become hardcore".