Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

seasurfer

macrumors 6502a
Original poster
Dec 12, 2007
705
133
I like to learn how to use it. Wonder if anyone know a good learning resource?
 

2984839

Cancelled
Apr 19, 2014
2,114
2,239
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.

Code:
 ls

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.

Code:
/bin/ls

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.

Code:
man ls

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.

Code:
cd /usr

This will run cd to change the current directory to /usr. You can always run pwd to print the current working directory

Code:
pwd

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.

Code:
ls

To change directories again, just run cd with the path you want to go to as its argument.

Code:
cd /path/to/wherever

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.
 

IHelpId10t5

macrumors 6502
Nov 28, 2014
486
348
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.
 

rwbarna

macrumors newbie
Aug 6, 2008
21
0
Bernalillo, NM
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."
 

jasnw

macrumors 65816
Nov 15, 2013
1,012
1,048
Seattle Area (NOT! Microsoft)
Try this "Take Command" book, it's specifically for using the Terminal (AKA "the command line") on a Mac:

https://www.takecontrolbooks.com/command-line

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.
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
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

Start here:

https://www.atomiclearning.com/macosxterminalx.shtml

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.