PDA

View Full Version : Terminal Help




Darbydoggy
Oct 5, 2004, 12:07 AM
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
Oct 5, 2004, 12:12 AM
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
Oct 5, 2004, 12:18 AM
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
Oct 5, 2004, 12:27 AM
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
Oct 5, 2004, 07:36 AM
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
Oct 5, 2004, 11:21 AM
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
Oct 5, 2004, 12:36 PM
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!

yellow
Oct 5, 2004, 01:04 PM
Here's a good tutorial for getting into Darwin:

http://osxfaq.com/Tutorials/LearningCenter/index.ws

Darbydoggy
Oct 5, 2004, 01:54 PM
Thanks again to everybody. I found the OSXFAQ site late last night and will be reading through it. Apple users are the best!!

zimv20
Oct 5, 2004, 02:06 PM
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
Oct 5, 2004, 02:14 PM
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
Oct 5, 2004, 02:15 PM
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
Oct 5, 2004, 03:05 PM
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
Oct 5, 2004, 03:17 PM
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
Oct 5, 2004, 03:45 PM
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
Oct 5, 2004, 04:04 PM
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
Oct 5, 2004, 04:11 PM
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
Oct 5, 2004, 04:13 PM
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
Oct 5, 2004, 04:17 PM
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
Oct 5, 2004, 04:23 PM
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
Oct 5, 2004, 04:31 PM
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
Oct 5, 2004, 04:38 PM
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
Oct 5, 2004, 04:53 PM
: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
Oct 5, 2004, 05:52 PM
: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
Oct 5, 2004, 07:59 PM
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:

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. ;)

wrldwzrd89
Oct 6, 2004, 04:42 AM
No need to go writing a shell script when a simple command will suffice:

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. ;)
Thanks for that bankshot - I didn't know the good old find command could do that.

mms
Oct 6, 2004, 09:32 PM
open -a is awesome. Thanks. I love anything that will let me do more from my keyboard since it seems more efficient to me.

cluthz
Oct 7, 2004, 05:10 PM
i found out that the easist way to create my "itunes library fix"
was to write in the commands i needed in Text edit file (i called it itunesfix)and run >chmod 755 on the file,
i moved the file to /bin/ and now the users have to type "itunesfix" in terminal and then the folders get 777 permission (rwxrwxrwx) and the mp3s get 666 (rw-rw-rw)! :D

anyway the open -a (and open e is nice!!)
i entered in the Terminal:
>alias o="open -a"
then i only have to type
>o "appname" to open apps!! :D

rand()
Oct 7, 2004, 11:31 PM
open -a is awesome. Thanks. I love anything that will let me do more from my keyboard since it seems more efficient to me.

It doesn't just seem more efficient - once you learn good keyboarding as well as useful commands, it truely is more efficient than the mouse for most tasks.

I once saw a device that had 4 piano-like keys - invented by one of the guys who initially worked on the Mouse as well - that was intended to be used as modifier / command keys in conjunction with the capabilities of the mouse. This would truely speed the abilities of the user - if it weren't for the freakin' learning curve!

As for my contribution to the "useful commands" - actually, my best offer is a script:

#!/bin/bash
kill `ps aux | grep $1 | grep -v grep | awk '{print $2}'`

Pop that baby into a text file (named "killapp" or whatever you like), chmod +xr it, and stick it somewhere in your PATH (like /bin or /sbin). Now you can use the command "killapp Explorer" to finally kill Internet Explorer! It's your very own command line Force Quit, without the dialog box.

-rand()

zimv20
Oct 8, 2004, 12:18 AM
kill `ps aux | grep $1 | grep -v grep | awk '{print $2}'`
i was working on a unix project once, we used a command similar to this. but there was one guy for whom it never worked.

it took a while to figure out, but what was happening was, due to the way the sysadmins made usernames, his username contained the string "grep", so _all_ processes belonging to him were getting stripped out.

my favorite alias:
alias k 'cd ..'

very simple, just used for moving to the above directory. but it's intuitive for vi users, since that's the key command to move up a line.

rand()
Oct 8, 2004, 08:17 AM
it took a while to figure out, but what was happening was, due to the way the sysadmins made usernames, his username contained the string "grep", so _all_ processes belonging to him were getting stripped out.

That's really funny, in the geekiest sense of the word. :)

In that case, you could make it a bit more string specific, like perhaps "grep " or " grep" just to throw that extra 'error-check' space in there.

-rand()

Bu88a
Oct 8, 2004, 08:49 AM
I've done astronomy research on a sun machine, so i sort of know what's going on with basic commands and scripting....

my question is that whenever i'm using the terminal (or X11) and want to edit a file, and use the & to get it to open a new window it just hangs...

it would be nice to open a new terminal session to edit something without losing the original terminal window...

any ideas???

yellow
Oct 8, 2004, 09:25 AM
Trying to open a new window and backgrounding the process (using the &) won't work in Terminal.app. It's not X11 and won't open unix binaries like that. But it should work just fine in an X11 xterm, I guess it depends on which text editor you're talking about. emacs? Unless you replaced the emacs that came with darwin, that's not an X-version.

zimv20
Oct 8, 2004, 01:09 PM
it would be nice to open a new terminal session to edit something without losing the original terminal window...

any ideas???
as mentioned, putting the process in the background won't accomplish that.

get used to operating w/ two windows (at least). one in which to edit, the other to do command line operations.

the pwd command is useful here. you can copy the directory you're in, then cd to it in the new window with the paste. if you've got a Finder window open to that folder, you can:
1. type cd in the terminal window
2. follow it with a space
3. drag the folder you want to go to into the terminal window
4. after the full path of the folder is displayed, hit return

Logik
Oct 8, 2004, 01:35 PM
Thanks again to everybody. I found the OSXFAQ site late last night and will be reading through it. Apple users are the best!!

lol.. actually most of the ones i've talked to have been elitists ;) good at knowing stuff but not good at understanding others don't know it already :-/ quite a few on here seem to be pretty helpful though which is rather useful