Ex-Dos User, Ready to Learn UNIX!

Discussion in 'Mac Apps and Mac App Store' started by jaw04005, Jun 16, 2004.

  1. jaw04005 macrumors 601

    jaw04005

    Joined:
    Aug 19, 2003
    Location:
    AR
    #1
    I'm wanting to learn how to use the command line features of Mac OS X, and start using open source applications. Is there a good book anyone would recommend for an ex-dos user? I know some of the commands are sort of similar. Any websites or recommendations would greatly be appreciated!
     
  2. LeeTom macrumors 68000

    LeeTom

    Joined:
    May 31, 2004
    #2
    Hey,
    I don't have any really solid recommendations, but I know exactly where you are at, I was there a few years back, and struggled through it (and I'm glad I did!).

    You might pick up the O'Reilly book, Learning The Bash Shell... with unix, there can be different shells with completely different commands, but bash is the most popular, and is what OS 10.3 uses by default.

    The command-line program I found the most useful is called 'vi'. It's a text editor... a bit more strange than 'edit' in DOS, but very handy once you get the hang of it!

    Good luck, and stick with it!
    Lee Tom
    ------------------------------------
    some handy commands:
    (you might try some out in Terminal, but be careful!)

    cd # change directory
    ls # list files in the current directory
    ls -al # list files, plus their details (owner, permissions)
    mv # move or rename a file (mv oldname.txt newname.txt)
    rm # remove a file
    rm -rf # remove, recursive & forced - needed for removing dirs.
    (dangerous!)
    chown # change the owner of a file or dir
    chmod # change the permissions of a file or dir
    cat # show contents of a text file
    tail # show last 10 lines of a text file
    tail -n 50 # show last 50 lines of a text file (good for logs)
    head # like tail, but beginning lines
    pwd # show what directory you are now in
    tar -zxvf # extract a tar.gz file
    tar -zcvf # create a tar.gz file
    ftp # ftp!
    whois # lookup who owns a domain name
    host # translates domain names into IP addresses, vice versa
    traceroute # trace the path between you and another IP address
    ping # check to see if an ip address responds


    i'm probably leaving some important ones out....
    the <tab> key is your friend... it autocompletes a file or directory name for you... makes getting around much easier.
     
  3. mkrishnan Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #3
    Not to start a best editor thread, but in case you get frustrated by vi and you're doing a relatively simple edit, pico is another one that's installed by default and very easy to use. Also emacs (which is very powerful, prolly not quite as easy for a new user as pico tho).

    If you've ever used Pine, Pico will be particularly familiar. ;)
     
  4. LeeTom macrumors 68000

    LeeTom

    Joined:
    May 31, 2004
    #4
    Thanks,
    Yeah, I forgot about pico. That's a good simple text editor.
    I will vouch for vi though, it was good to learn. I'm sure emacs rules too (the vi/emacs war is comparable to mac/windows war, except in this case both sides are pretty good).
    vi and emacs are the next level, after you get frustrated with pico being too simple.

    Lee Tom
     
  5. gekko513 macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #5
    In unix filesystems, there are no C: D: drives at the root of the file paths. Instead, the filesystem just starts with a /
    To list the contents of the root directory, type ls -al /
    Each file or directory is listed with
    ACCESS_RIGHTS X OWNER GROUP SIZE LAST_MODIFIED FILENAME
    I'm not really sure what the number X is. I'm on linux now, so there may be some differences. The /users directory contains a directory for all users on the computer. To go here, type cd /users
    List the contens of the current directory by ls -al

    Another thing worth mentioning about the unix-like filesystems is that the physical drives and stations can be mounted virtually anywhere in this filesystem.

    Some more handy commands:
    ssh <host> (to log in on a remote host (running linux or unix/macosx))
    ssh <user@host> (using a different username)
    scp <file-path> <host:file-path> (to copy a file to a remote host)
    scp <host:file-path> <file-path> (to copy a file from a remote host)
    find <directory-path> (essentially lists all files in the directory recursively)

    It can be very useful to use the output from one command as the input to another command. This is done with the | pipe sign.
    find <dir> | grep <pattern> (will print out all lines from the find command that matches the given pattern)

    cat <file> (will just dump the contents of a file)
    cat <file> | grep <pattern> (will therefore print all lines from the cat command that matches)
    cat <file> | less (dumps the contents of a file into the program 'less' which let's you scroll up and down in whatever it is displaying with arrow keys and page up/down. Type 'q' to quit 'less')

    man <command-name> (gives a (somewhat cryptic) explanation of what a command does and which options it can take)

    To redirect the output from a command to a file, use >
    ls /users > myfile (puts the listing of files in the /users directory in a file name myfile)
    cat myfile (shows the contents of the file you just created)
     
  6. jaw04005 thread starter macrumors 601

    jaw04005

    Joined:
    Aug 19, 2003
    Location:
    AR
    #6
    Thanks for all the information guys, I've been playing around with Terminal for a few hours and I'm getting there. Its sort of alot to learn at once, but I'm sure it will be worth it. Thanks for the tip about / , I was wondering how to move up to the root directory.

    This is probally a dumb question, but when I'm doing things in the Finder GUI, behind the scenes are these the commands that are happening? Like if I delete a file in finder, OS X is really "rm"ing?
     
  7. Horrortaxi macrumors 68020

    Horrortaxi

    Joined:
    Jul 6, 2003
    Location:
    Los Angeles
    #7
    Unix for Mac OS X, by Matisse Enzer--Peachpit Press. More detail than you'll probablyever need but a good read nonetheless.
     
  8. gekko513 macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #8
    No. Both the Finder and rm must in the end call Darwin. Darwin is the kernel of Mac OSX. The kernel is the core of the OS. (You may remember that when Windows 98 used to blue-screen it said there had been an error in kernel32.) The kernel handles all important functionality of the computer. The terminal and bash is one way to access this functionality. Aqua and the Finder is another, prettier way.
     
  9. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #9
  10. cb911 macrumors 601

    cb911

    Joined:
    Mar 12, 2002
    Location:
    BrisVegas, Australia
    #10
    kingjr3, thanks for that link, looks good.

    one tip that i have to say about using the Terminal, is that if you want to type the path of a folder, and most likely some of your folders will have names that contain spaces, you have to type something like:

    Code:
    ~/My\ Documents
    instead of just typing

    Code:
    ~/My Documents
    you need the '\' in there to tell Terminal that there's more to follow, or else it will just look for '~/My'. that was one thing that drove me crazy when i was learning UNIX commands & using Terminal. :p and don't forget that you can drag and drop folder into a Termainal window and it will automatically show the path of the folder.

    or if you really want to learn Linux/UNIX you could just go ahead an install Linux on your Mac - that'll really force you to learn. that's what i did, dove right in the deep end and installed Gentoo. :D that's probably the best distro if you really want to get down to the basics and seriously jump in the deep end. :)
     
  11. MisterMe macrumors G4

    MisterMe

    Joined:
    Jul 17, 2002
    Location:
    USA
    #11
    If you want to learn Linux, yes. If you want to learn UNIX, then it is unnecessary. Your new Mac ships with a complete commandline Darwin BSD pre-installed. BSD is real unix. Today, Macs ship with X11 preinstalled. Add your favorite window manager and you can do anything that any other BSD user can do.
     
  12. mkrishnan Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #12
    You can also use quotations to deal with this, just like in Windows. IE

    cd "My Documents"

    Although there seems to be some strangeness with this. Like you can do the above example but

    cd "~\Documents"

    doesn't work while

    cd ~\Documents

    does. :confused:

    Another goofy Unix thing that I always forget if I'm away from Unix for a long time is that most applications, if not part of the default path, need to be run like:

    ./appname

    When you are already in the directory, instead of just appname.

    BTW, let me ask a question. How do you launch a .app application from BASH?
     
  13. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #13
    open someapplication.app
     
  14. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #14
    On OSX you can use the "open" command, which hooks into LaunchServices to figure out what needs to be done to open the file. "open ." for example, opens the current path in the Finder
     
  15. mkrishnan Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #15
    Thanks! Knew it had to be something simple like this...I tried exec, launch, run and start and it wasn't any of those. :D
     
  16. gekko513 macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #16
    What "..." does is to tell bash to consider whatever is inside as one argument and also to not process special characters like '~', '*' and more.
    That's why cd "~/Documents" doesn't work because the ~ isn't replaced with your home directory. cd ~"/Documents" would work, however.

    Single quotes '...' are like double quotes, except that single quotes will not process $ as variables either.

    The reason I've hear to not allow a program to be run without the ./ is to protect against "virus" programs. If a cracker were able to upload or make you download a file named ls, or some common typo, it would eventually be run by a user or even by the root-user. Which would not be a good thing. You can allow local programs to be run by adding . to the PATH variable, but it's not recommended.

    Mac OSX apps are actually just directories with all files and resources for the application. You'll find the executable in there somewhere too, just look around and you'll see it.
     
  17. cb911 macrumors 601

    cb911

    Joined:
    Mar 12, 2002
    Location:
    BrisVegas, Australia
    #17
    thaks for explaining that. i just found out about using quotes today, will keep that in mind. :)

    and on the point of using what comes with OS X, because it is based on BSD... that's what i thought i'd do. but with all the pretty Aqua-ness why would you want to mess around with icky command line stuff? :p i just spent all my time in OS X messing around with themes and GUI customization. :D

    for people who have a hard time concentrating on the Terminal with all the other GUI stuff floating around, installing Gentoo for example will force you to learn a thing or two. unless you want to use a different window manager for OS X... like Fluxbox or something really minimal to get rid of those Aqua distractions... i've heard that's possible...
     
  18. Bruce Lee, PhD macrumors member

    Joined:
    Jun 10, 2004
    #18
    "The Unix Programming Environment" by Kernighan and Pike is a classic. It's relatively advanced, and you can argue it's a bit outdated. But take a look; it might be just the thing to get you familiar with shell basics, shell scripting and working with the tools. I learned from it and found it to be more useful and to-the-point than "friendlier" books.

    http://www.amazon.com/exec/obidos/t...f=sr_1_3/104-6924746-9800711?v=glance&s=books

    IMO the most important thing when learning any Unix is to get ready to suffer. :) It's a nice, efficient environment for a lot of things once you know it, but it takes some time. There are a lot of tools with inconsistent and arcane command-line syntax, and there are often multiple versions of standard utilities. Find a helpful users' group and ask questions.
     

Share This Page