2 Terminal / UNIX questions

Discussion in 'Mac Programming' started by MadDoc, Mar 27, 2007.

  1. macrumors 6502

    MadDoc

    Joined:
    Apr 25, 2005
    Location:
    UK
    #1
    Hi,

    I have pretty much never used the terminal and barely know any UNIX commands apart from 'clear', 'cd' and 'ls' so bare with me :)

    1. How do I navigate to a directory in the terminal using the 'cd' command is the destination directory has spaces in it. For instace, if on the desktop I have a directory called 'my pics' and I navigate to the desktop in the terminal and type 'cd' it list the above directory. If I then type:

    Code:
    cd my pics
    I get an error as it says "-bash: cd my: No such file or directory". I'm obviously doing something very simply wrong but I don't know how to represent spaces in directories.

    2. I am trying to write a simple app in REALbasic that will allow me to launch an app on my system with a passed file. For instance, I have a freeware Sega Genesis emulator (Genesis Plus) and I want to be able to pass to that emulator the rom to load. This shouldn't be hard to do via the terminal but are there commands for passing files to open to an application? If so, how would I go about this?

    Thanks in advance,

    MadDoc
     
  2. macrumors G4

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    Common problem which I have to deal with - the solution is to escape the space with a backslash. For example, let's say you have a directory called My Pics inside the Blah folder at the root of the hard drive. To go there from the terminal, type:
    Code:
    cd /Blah/My\ Pics/
    As for your second question, most Mac applications support sending a file to open as an argument. Just add the full path to the file at the end of the call to the application. Example, for Genesis Plus:

    Code:
    open -a Genesis\ Plus /path/to/file
     
  3. thread starter macrumors 6502

    MadDoc

    Joined:
    Apr 25, 2005
    Location:
    UK
    #3
    Thanks wrldwzrd89!

    Question 1 - sorted.

    Question 2 - take a look at the following code:

    Code:
    ~/desktop Garry$ open -a genesis\ plus emulators/roms/megadrive/aladdin.bin
    This works fine. As you can see, the rom is in a child directory of the desktop. How would I open this file if the file wasn't in a child of the desktop. Can oyu use an absolute path or some sort?

    MadDoc,
     
  4. macrumors G4

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #4
    Yes:

    Code:
    /Users/(your short user name)/Desktop/emulators/roms/megadrive/aladdin.bin
    Alternatively, just drag the file to the Terminal window, and the full path will magically appear.
     
  5. thread starter macrumors 6502

    MadDoc

    Joined:
    Apr 25, 2005
    Location:
    UK
    #5
    Thanks again,

    Last couple of questions (honest!).

    How would kill an app from the terminal (for instance, Genesis Plus)?

    Can you recommend a good place to start to learn about terminal commands?

    Oh, what does '-a' mean?

    Thanks a million,

    MadDoc,
     
  6. macrumors G4

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #6
    To kill an application by name, use:

    Code:
    killall appname
    Note that this kills ALL running instances, should you have more than one open.

    The man pages and info pages are a HUGE help in learning what the different commands do. Just type:

    Code:
    man commandname
    or

    Code:
    info commandname
    to learn what the command called commandname does (replace commandname with the name of a command).

    The -a argument means "Application". It tells the open command to search the Applications folder for your application, then open it.
     
  7. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #7
    Hi

    On the subject of 1), you can also use tab completion. In the terminal, after typing:-
    cd my
    hit the return key, the shell will attempt to complete the file name for you. If you have no other file names that begin with 'my' the shell will complete the line 'cd my\ pics'. If you have more than one file begining with 'my ' it will complete up until after the space, ie 'cd my\ '. tab completion is useful!

    b e n
     
  8. macrumors demi-god

    szark

    Joined:
    May 14, 2002
    Location:
    Arid-Zone-A
    #8
    You can also put quotes around it:

    Code:
    cd "/Blah/My Pics/"
     
  9. macrumors member

    cruzrojas

    Joined:
    Mar 26, 2007
    Location:
    USA
    #9
    For the first question you asked you could also use

    >cd "My pics"

    or to make your life easier you could use a little trick of the terminal window, assuming the folder My pics is the only one that starts with my, you could easily just type My and then the Tab key in your keyboard, and the terminal will take care of complete your path. The tab key could also help you to complete commands, for example type mor and then the tab key, the terminal will then complete the command more, this is useful when you use large commands, or when you don't remember the command exactly.

    Finally to kill a process you can use the kill command.
    First do

    >ps

    and this will give you a list of the processes running in the terminal, then take note of the PID number of the process you want to kill

    >kill 29xxx

    Cheers
     
  10. thread starter macrumors 6502

    MadDoc

    Joined:
    Apr 25, 2005
    Location:
    UK
    #10
    @ szark:

    Thanks for the tip about the quotation marks - very helpful.

    @ all:

    When I type:

    Code:
    killall genesis plus
    or

    Code:
    killall "genesis plus"
    or

    Code:
    killall genesis\ plus
    I get the following error: "No matching processes belonging to you were found"

    Using activity monitor, I can see that the name of the emulator running is listed as "Genesis Plus"

    Where have I gone wrong?

    P.S. How do you exit from the man command?

    MadDoc,
     
  11. macrumors G4

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #11
    Case matters. You need "Genesis Plus", not "genesis plus".

    As for the man command, hitting escape will quit out of it.
     
  12. thread starter macrumors 6502

    MadDoc

    Joined:
    Apr 25, 2005
    Location:
    UK
    #12
    You are a legend wrldwzrd89.

    Many thanks,

    MadDoc
     

Share This Page