Separate names with a comma.
Discussion in 'Mac Programming' started by seasurfer, Jan 5, 2016.
I like to learn how to use it. Wonder if anyone know a good learning resource?
Honestly, the best resource is the terminal. Open one and start trying stuff. Here's a rundown of some basics to get started.
A terminal is an interface to the shell. The shell is really what interprets the commands you type and executes them. There are various Unix shells out there, such as the Bourne shell (called "sh"), Bourne Again Shell (bash), the Z shell (zsh), the Korn shell (ksh), the C shell (csh), and others. The default shell when you open a terminal in OS X is bash. When you open a terminal in Unix, it will execute the shell binary, which is typically located in /usr/bin. This means you could change the shell if you wanted to. For example, you could configure the terminal so that it would execute /bin/zsh if you wanted to use the Z shell instead. You don't need to if you're just starting to use the terminal, but the point I'm emphasizing is that the shell does all the work; the terminal just lets you use it.
The shell will break up what you type into 2 pieces. The first is the command and is the first word you type. The shell will execute two types of commands: built-in and external. Built-in commands are part of the shell itself, hence the name. "cd" is an example of a built in command; it changes the shell's current directory.
The 2nd type of commands are external programs. These are executable binaries not built in to the shell. The actual binaries reside in the system directories with "bin" or "sbin" in them. On most Unix like systems, they will be in /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin. The actual location varies a bit depending on the OS. A variable called PATH defines which directories you want the shell to look inside when you type a command. The shell will look in all the directories in your PATH for a binary matching the first word you type. Here are some examples.
This will print a list of the contents of the current directory. Note that you could also specify the full path to the ls binary like so.
This should give the same results because it is executing the exact same program. The PATH variable just lets you type the name of the program without having to tell the shell where to look for it.
So, the first word you type is the command. The next chunk of text after the first space is interpreted by the shell as the argument. Almost all commands take arguments. Many programs will want their arguments preceded by a single dash, but not all. To find out what kind of arguments a program takes, you can read its manual page. To do this for the ls command I used earlier, I would use the "man" program, which will display the manual page for the program named by its argument.
If you run this command, you will be given a page of info about ls. In this example, "man" is the command and "ls" is the argument to the "man" program. Reading the manual pages for various programs is the single most important way to learn how to use a shell.
Here's another example of a command and an argument.
This will run cd to change the current directory to /usr. You can always run pwd to print the current working directory
This should now print out /usr. To see what is inside this directory, you can run ls again and it will print out the contents.
To change directories again, just run cd with the path you want to go to as its argument.
Knowing how to run man, ls, and cd are all you really need to learn the rest. Here are some commands to try. Make sure to read the man pages first!
mv -- move a file
rm -- delete a file
cp -- copy a file
mkdir -- create a new directory
To see what other programs you have at your disposal, run ls with any of the various "bin" directories as an argument and it will list everything in them. Then run "man" with the program name as an argument.
I am a new user of a Macbook and its Unix terminal too.
This is written for the Raspberry Pi but I found this to be a good resource to learn about the terminal command line:
Also, Codecademy have an easy tutorial on the command line which I found really useful too:
Hope that helps!
The terminal is a BASH shell. I'd start with opening the terminal and typing: man bash
O'Reilly Publishing - "Learning the bash Shell" is a great book for learning and for reference. After that intro all you should need are man pages and the ability to Google for examples. Another good source is to download some GIT repos of popular projects that use bash as examples.
I guess what you're asking is not how to use Terminal, but for a beginners guide to UNIX. Terminal, as others have mentioned, is just a way of interacting with a UNIX shell.
Personally, I found this book very useful: http://shop.oreilly.com/product/0636920025870.do
The tricky part is that OS X is more of a BSD than a Linux - so just enough stuff is different to be a little confusing
Another good resource is the Nosillacast podcast, with a series called "Taming the Terminal" hosted by Allison Sheridan.
"Taming the Terminal is a collaboration between Bart Busschots and Allison Sheridan. The tutorials were written by Bart and hosted on his site at https://www.bartbusschots.ie/s/blog/taming-the-terminal/. The series of tutorials originally aired on several NosillaCast podcast episodes.
In the series, Bart guides Allison through a collection of tutorials to help people become comfortable using the Terminal and to learn efficient ways of controlling their computer and diagnosing network problems. While both hosts are using OS X, every effort is made to include both Linux and Windows comparative commands where possible.
Bart is a Linux system administrator by day, is hosts the Let’s Talk Apple and Let’s Talk Photography podcasts. Allison is the host of the NosillaCast podcast, A Technology Geek Podcast with an EVER so Slight Macintosh Bias."
Download iTerm2 - much better than the OS X Terminal.app
Try this "Take Command" book, it's specifically for using the Terminal (AKA "the command line") on a Mac:
RE using a third-party terminal app, I'd just stick with Terminal.app. It does everything you need to do.
If you really want to get serious about scripting, I'd suggest that after you get comfortable working on the command line that you look into the python scripting language. It's far more capable than the various "shell" scripting languages (like bash) and has a huge user community. It comes with OS X, so you don't need to install anything new.
OSX is BSD modified by Apple for their needs as such the utilities included are the BSD ones. The difference being most times certain switches/command line options that would work in Linux will not in the BSD variant of the utility as they are not included in the binary.