PDA

View Full Version : 2 Terminal / UNIX questions




MadDoc
Mar 27, 2007, 01:36 PM
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:

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
Mar 27, 2007, 01:43 PM
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:

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:
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:

open -a Genesis\ Plus /path/to/file

MadDoc
Mar 27, 2007, 02:10 PM
Thanks wrldwzrd89!

Question 1 - sorted.

Question 2 - take a look at the following 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
Mar 27, 2007, 02:15 PM
Thanks wrldwzrd89!

Question 1 - sorted.

Question 2 - take a look at the following 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:

/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
Mar 27, 2007, 02:21 PM
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
Mar 27, 2007, 02:25 PM
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:

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:

man commandname

or

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
Mar 27, 2007, 02:29 PM
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
Mar 27, 2007, 02:32 PM
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:
cd /Blah/My\ Pics/

You can also put quotes around it:

cd "/Blah/My Pics/"

cruzrojas
Mar 27, 2007, 02:40 PM
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
Mar 27, 2007, 02:48 PM
@ szark:

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

@ all:

When I type:

killall genesis plus

or

killall "genesis plus"

or

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
Mar 27, 2007, 02:53 PM
@ szark:

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

@ all:

When I type:

killall genesis plus

or

killall "genesis plus"

or

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.

MadDoc
Mar 27, 2007, 02:57 PM
You are a legend wrldwzrd89.

Many thanks,

MadDoc