Best Resource to Learn Terminal?

Discussion in 'Mac Programming' started by seasurfer, Jan 5, 2016.

  1. seasurfer macrumors 6502a

    Joined:
    Dec 12, 2007
    #1
    I like to learn how to use it. Wonder if anyone know a good learning resource?
     
  2. kmaute macrumors 6502

    kmaute

    Joined:
    Oct 5, 2008
    Location:
    USA
  3. 556fmjoe macrumors 65816

    Joined:
    Apr 19, 2014
    #3
    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.
     
  4. anthlis macrumors newbie

    Joined:
    Jan 5, 2016
    #4
  5. nightcap965 macrumors 6502a

    nightcap965

    Joined:
    Feb 11, 2004
    Location:
    Cape Cod
    #5
    The terminal is a BASH shell. I'd start with opening the terminal and typing: man bash
     
  6. IHelpId10t5 macrumors 6502

    Joined:
    Nov 28, 2014
    #6
    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.
     
  7. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #7
    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
     
  8. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #8
  9. rwbarna macrumors newbie

    Joined:
    Aug 6, 2008
    Location:
    Bernalillo, NM
    #9
    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."
     
  10. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #10
    Download iTerm2 - much better than the OS X Terminal.app
     
  11. jasnw macrumors 6502

    Joined:
    Nov 15, 2013
    Location:
    Seattle Area (NOT! Microsoft)
    #11
    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.
     
  12. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #12
    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.
     

Share This Page