Terminal Help

Darbydoggy

macrumors newbie
Original poster
Aug 29, 2004
28
0
California
I need some basic understanding or help with Terminal that I don't get. I am the only user on my PB (and thus the OS X admin). In Terminal, I can cd to any existing folder that was there when I first started with the OS (ie-any pre-existing folder). I can't, however, cd to any new folder that I created. For example, I can cd to Documents, and when I ls I see all the subfolders listed that I have created. When I cd to one of those subfolder I get an error in Terminal as follows:

-bash: cd: Ipod: No such file or directory

For a full example, here is an entire short sequence from Terminal that shows what I mean:

Pete-Computer:~ Pete$ cd Documents
Pete-Computer:~/Documents Pete$ ls
Ipod Info Pete's Documents
Pete-Computer:~/Documents Pete$ cd Ipod Info
-bash: cd: Ipod: No such file or directory
Pete-Computer:~/Documents Pete$

Can anybody explain why, or tell me if this is normal and how I can access newly created directories in Terminal?

Thanks!
 

bousozoku

Moderator emeritus
Jun 25, 2002
13,951
3
Gone but not forgotten.
If you have folders/directories with spaces in the name, use quotation marks around the name, so it knows to use everything.

cd "Documents/Ipod Info" will get you there

or even,

cd "Documents"
cd "Ipod Info"
 

Darbydoggy

macrumors newbie
Original poster
Aug 29, 2004
28
0
California
Thank you! That was it. I mistakenly thought it had to do with newly created folders, but I was only trying folder names that had spaces in them. I have a LONG WAY TO GO with my learning of some Unix, then understanding some obj C and then playing with Cocoa. :)
 

bousozoku

Moderator emeritus
Jun 25, 2002
13,951
3
Gone but not forgotten.
Darbydoggy said:
Thank you! That was it. I mistakenly thought it had to do with newly created folders, but I was only trying folder names that had spaces in them. I have a LONG WAY TO GO with my learning of some Unix, then understanding some obj C and then playing with Cocoa. :)
I'm sure you have plenty of company also getting a history lesson in UNIX. :D Imagine all those MS-DOS/PC-DOS users who thought they knew how to use the command line--they're learning too.
 

tomf87

macrumors 65816
Sep 10, 2003
1,052
0
bousozoku said:
If you have folders/directories with spaces in the name, use quotation marks around the name, so it knows to use everything.

cd "Documents/Ipod Info" will get you there

or even,

cd "Documents"
cd "Ipod Info"
Anothery way to make note of is to use the backslash:

cd Documents
cd Ipod\ Info

If you go into Terminal and do:

cd Document
cd Ipod<hit Tab now>

On that second line, if you hit the Tab key, it will try to autocomplete it for you as well.
 

bousozoku

Moderator emeritus
Jun 25, 2002
13,951
3
Gone but not forgotten.
tomf87 said:
Anothery way to make note of is to use the backslash:

cd Documents
cd Ipod\ Info

If you go into Terminal and do:

cd Document
cd Ipod<hit Tab now>

On that second line, if you hit the Tab key, it will try to autocomplete it for you as well.
You should mention that you use a backslash to form an escape character and that it works with several of the things that normally can't be typed outright. ;)
 

bankshot

macrumors 65816
Jan 23, 2003
1,259
73
Southern California
Another tip: type a little bit of the file or folder name (enough to be unique) and hit the tab key. It'll expand the rest of it for you. If what you didn't type is fully unique (for example, you just typed 'a' and there are 5 files starting with 'a'), it will beep at you once. Hit tab a second time and it will list all the possibilities for you. Very handy!
 

Darbydoggy

macrumors newbie
Original poster
Aug 29, 2004
28
0
California
Thanks again to everybody. I found the OSXFAQ site late last night and will be reading through it. Apple users are the best!!
 

zimv20

macrumors 601
Jul 18, 2002
4,388
7
toronto
tomf87 said:
if you hit the Tab key, it will try to autocomplete it for you as well.
wow, i learn something new every day.

i've been using filename autocompletion for 20 years, but i always use the escape key (hit it twice). is the tab autocompletion an Apple thing, or did that creep into various versions of unix when i wasn't looking?
 

yellow

Moderator emeritus
Oct 21, 2003
15,925
1
Portland, OR
zimv20 said:
is the tab autocompletion an Apple thing, or did that creep into various versions of unix when i wasn't looking?
It's part of tcsh (and probably bash) across all UNIX platforms (at least Darwin, Solaris, and OSF, the only ones I've used it on lately) for quite a while.
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,106
73
Solon, OH
zimv20 said:
wow, i learn something new every day.

i've been using filename autocompletion for 20 years, but i always use the escape key (hit it twice). is the tab autocompletion an Apple thing, or did that creep into various versions of unix when i wasn't looking?
Here's another handy Terminal tip. Hit Control+R while at a BASH prompt, and you'll get a "reverse-i search" prompt. Start typing, and BASH will search the list of recently typed commands for the one you're looking for. When you find the one you want, press Return to accept it. You can edit it before running it by pressing Return again.
 

cluthz

macrumors 68040
Jun 15, 2004
3,118
3
Norway
Thanks wiz!

Using terminal all day, but have never used the reverse-i search.
This would save me a lot of time! (hehe, atleast 30 sec a day maybe.. :D )

Anyway is it possible to launch apps from the terminal like you do on gnu/linux and others unixes? like >mozilla & (i know the & is to not occupy the latest xterm seesion).
I know i can run >open Mozilla.app (if Mozilla.app is in pwd.), but that takes too muck time to do.
I know that files added to the $PATH can be run like this. But ".app"s are folders and i don't think it would work if i added /Applications/ to $PATH either
 

yellow

Moderator emeritus
Oct 21, 2003
15,925
1
Portland, OR
cluthz said:
Anyway is it possible to launch apps from the terminal like you do on gnu/linux and others unixes? like >mozilla & (i know the & is to not occupy the latest xterm seesion).
I know i can run >open Mozilla.app (if Mozilla.app is in pwd.), but that takes too muck time to do.
I know that files added to the $PATH can be run like this. But ".app"s are folders and i don't think it would work if i added /Applications/ to $PATH either
open -a Mozilla

No need for it to be in your path. I beleive as long as it's in the /Applications and/or /Applications/Utilites.
 

cluthz

macrumors 68040
Jun 15, 2004
3,118
3
Norway
yellow said:
open -a Mozilla

No need for it to be in your path. I beleive as long as it's in the /Applications and/or /Applications/Utilites.
Sweeet. :cool:
No need for launchbar or quicksilver now...
 

cluthz

macrumors 68040
Jun 15, 2004
3,118
3
Norway
Now i don't have to use vi to edit invisible files (like different configfiles)!!!

open -a subethaedit .profile :D

Is this standard unix? Or a macosx thing?

The posibilities and how powerful the terminal in macosx is, are often well hidden.
Osx is far more powerful than any other OS i have used.
With the X11 server and OSX own functions you can run everything (except win only progs, hope the DarWine project will get a breakthru soon).
Most OSX users doesn't discover the possibilities you have.
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,106
73
Solon, OH
cluthz said:
Now i don't have to use vi to edit invisible files (like different configfiles)!!!

open -a subethaedit .profile :D

Is this standard unix? Or a macosx thing?

The posibilities and how powerful the terminal in macosx is, are often well hidden.
Osx is far more powerful than any other OS i have used.
With the X11 server and OSX own functions you can run everything (except win only progs, hope the DarWine project will get a breakthru soon).
Most OSX users doesn't discover the possibilities you have.
It's Mac OS X-specific. Actually, if you want to edit something, you use the -e switch to open:

open -e .profile

...and Mac OS X opens it in TextEdit so you can modify it. I don't see any reason why:

open -a (application) (file)

...wouldn't work, but I haven't tried it. By the way, you can't combine -a and -e. You'll just get an error message if you try.
 

yellow

Moderator emeritus
Oct 21, 2003
15,925
1
Portland, OR
I believe you can also couple this with sudo.

Though, just testing, it replaces the permissions with those of your own, so this might not be such a useful thing.
 

cluthz

macrumors 68040
Jun 15, 2004
3,118
3
Norway
wrldwzrd89 said:
It's Mac OS X-specific. Actually, if you want to edit something, you use the -e switch to open:

open -e .profile

...and Mac OS X opens it in TextEdit so you can modify it. I don't see any reason why:

open -a (application) (file)

...wouldn't work, but I haven't tried it. By the way, you can't combine -a and -e. You'll just get an error message if you try.
open -a (app) (file) works great!
 

osprey76

macrumors 6502
May 3, 2004
298
0
Oklahoma City, OK
bankshot said:
Hit tab a second time and it will list all the possibilities for you. Very handy!
Nice! I'll have to try this tonight (on a PC at work.) I've used the single-Tab for a long time (not that I'm a big Terminal guru) but didn't know about the double-Tab option.
 

cluthz

macrumors 68040
Jun 15, 2004
3,118
3
Norway
while were talking about terminal commands.
I have a machine here which holds my whole household's mp3 files.
I mount a HD partition from this machine on my powerbook and have my iTunes library on this partition.
The problem is that sometimes when we add files (with itunes) to this mp3 folder from different computers and different users the permissions get bad and some users can't rename/organize the files which has get limited permissions.
my solution has been to use:
>sudo chmod 777 * //and then:
>sudo chmod 777 */*
Then i have fixed the firectory For "Artist" and "Album", but no the Songs.
The problem is whan i run:
>sudo chmod 777 */*/*
I get a warning that argument list is too long...
Ofcourse of i can use a*/*/*, and then b*/*/*, but it takes too long time.
I tried to check the "ignore permissions on this volume", but it didn't work that well either.
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,106
73
Solon, OH
cluthz said:
while were talking about terminal commands.
I have a machine here which holds my whole household's mp3 files.
I mount a HD partition from this machine on my powerbook and have my iTunes library on this partition.
The problem is that sometimes when we add files (with itunes) to this mp3 folder from different computers and different users the permissions get bad and some users can't rename/organize the files which has get limited permissions.
my solution has been to use:
>sudo chmod 777 * //and then:
>sudo chmod 777 */*
Then i have fixed the firectory For "Artist" and "Album", but no the Songs.
The problem is whan i run:
>sudo chmod 777 */*/*
I get a warning that argument list is too long...
Ofcourse of i can use a*/*/*, and then b*/*/*, but it takes too long time.
I tried to check the "ignore permissions on this volume", but it didn't work that well either.
First of all, you shouldn't be setting execute permissions on the song files. The reason you're getting that warning is that you're running into an internal limit on the length of command-line arguments in Mac OS X, which is 65535 characters. Odds are that when that expression is fully expanded, the resulting text is too long for Mac OS X to handle. The easiest way to do this is to write a little shell script that changes to each directory and changes permissions on everything in it. You'll need to make use of the pushd and popd commands so you can keep track of where you've been and where you need to go next.
 

cluthz

macrumors 68040
Jun 15, 2004
3,118
3
Norway
:eek: yeah i guess the permission should be 666 (110 110 110) instead of 777.

I'm not much into scripting (yet),
but isn't it possible to record a executable script?
(like the >script "output.txt")
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,106
73
Solon, OH
cluthz said:
:eek: yeah i guess the permission should be 666 (110 110 110) instead of 777.

I'm not much into scripting (yet),
but isn't it possible to record a executable script?
(like the >script "output.txt")
I'm not entirely sure what you're talking about, but you can record a UNIX command's output like so:

command > file

If you want to record error messages:

command 2> file

You can even do this:

command | tee file

What that does is displays the output of 'command' on the screen, and ALSO records it to 'file'.
 

bankshot

macrumors 65816
Jan 23, 2003
1,259
73
Southern California
wrldwzrd89 said:
First of all, you shouldn't be setting execute permissions on the song files. The reason you're getting that warning is that you're running into an internal limit on the length of command-line arguments in Mac OS X, which is 65535 characters. Odds are that when that expression is fully expanded, the resulting text is too long for Mac OS X to handle. The easiest way to do this is to write a little shell script that changes to each directory and changes permissions on everything in it. You'll need to make use of the pushd and popd commands so you can keep track of where you've been and where you need to go next.
No need to go writing a shell script when a simple command will suffice:

Code:
sudo find . -type f -exec chmod 666 {} \; -print
For the folders, use -type d (d for directories) and mode 777.

That said, the Unix security alarms in my head are going off like mad looking at these permissions. :eek: :p My inclination would be to create a group that includes all the users who need to access the music files, change all the files/directories to be owned by that group, and make the permissions 664 (or 775 for directories). Left as an exercise for the reader unless you seriously want to try it. Then I'll be happy to go into more detail. ;)