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

MadDoc

macrumors 6502
Original poster
Apr 25, 2005
329
5
UK
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
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
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
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
 

MadDoc

macrumors 6502
Original poster
Apr 25, 2005
329
5
UK
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,
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
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,
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.
 

MadDoc

macrumors 6502
Original poster
Apr 25, 2005
329
5
UK
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,
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
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,
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.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
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
 

szark

macrumors 68030
May 14, 2002
2,886
0
Arid-Zone-A
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/

You can also put quotes around it:

Code:
cd "/Blah/My Pics/"
 

cruzrojas

macrumors member
Mar 26, 2007
67
0
USA
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
 

MadDoc

macrumors 6502
Original poster
Apr 25, 2005
329
5
UK
@ 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,
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
@ 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,
Case matters. You need "Genesis Plus", not "genesis plus".

As for the man command, hitting escape will quit out of it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.