Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Very basic Terminal question

Very basic Terminal question
Thread Tools
Dedicated MacNNer
Join Date: Aug 2003
Status: Offline
Reply With Quote
Feb 18, 2008, 11:32 AM
 
Hey all. Real basic terminal quesion here.

How the heck do I go inside a directory that has spaces or multiple words? i.e. all I want to do is navigate inside a folder titled Nature Documentaries via terminal. I first go to the local directory that has the folder: cd movies, I'm in, then I type in: cd Nature Movies and I keep getting a 'No such file or directory' error message. I've tried adding in slashes, symbols, but it's a no-go.

It's a total noob question I realize this! I'm taking some Unix classes and I'm stuck on the first assignment!
     
Mac Elite
Join Date: Jun 2006
Status: Offline
Reply With Quote
Feb 18, 2008, 11:35 AM
 
cd Nature\ Documentaries

You could also type something like

cd Nat*

to select anything that starts with "Nat", which would select your Nature Documentaries folder if it's the only thing that starts that way.
MBP 2.4/160/2/256
iMac 2.0/250/1/128
     
drp
Fresh-Faced Recruit
Join Date: Jul 2006
Status: Offline
Reply With Quote
Feb 18, 2008, 12:11 PM
 
Originally Posted by herbsman View Post
How the heck do I go inside a directory that has spaces or multiple words? i.e. all I want to do is navigate inside a folder titled Nature Documentaries via terminal.
This may be more information then you were looking for, but for the sake of being complete:

The other poster mentioned part of the answer, but there are several ways to handle filenames with spaces or other characters that have secondary meanings to the shell.

1) You can "escape" the offending character. The standard shell escape character is "\". Any special character preceded by a backslash will be used literally and not interpreted. As the other poster mentioned, you can

cd Nature\ Documentaries

2) You can quote the string. There are two kinds of quotes for this purpose: single and double quotes. Single quotes interpret their contents literally. Double quotes still allow for variable substitution. As a result, you could

cd "Nature Documentaries"

-or-

cd 'Nature Documentaries'

However, due to the subtle difference with variable handling, cd "$HOME" will go to your home directory, while cd '$HOME' will look for a directory called $HOME.

3) There is a special case with the "-" character. If it starts a word, most programs will attempt to treat it as an option and not a filename. If your example was named "-Nature Documentaries" you need to let the command line know that "-Nature" isn't a program option with "--".

cd -- "-Nature Documentaries"

4) Of course, you can use wildcards if only one item will match.

cd Nature?Documentaries

-or-

cd Nature*

5) Lastly, if you're using quotes, the entire program argument needs to be quoted. This is different than Microsoft Windows command line

cd "/Users/Your Name/Nature Documentaries"

not

cd /Users/"Your Name"/"Nature Documentaries"
     
Dedicated MacNNer
Join Date: Aug 2003
Status: Offline
Reply With Quote
Feb 18, 2008, 12:22 PM
 
you all rock! much thanks!
     
Dedicated MacNNer
Join Date: Mar 2005
Location: Atlanta
Status: Offline
Reply With Quote
Feb 19, 2008, 07:54 AM
 
You can also press Tab to autocomplete words.

For example:

Type "cd Nat" without the quotes and then press Tab and if there is only one file starting with Nat then it will autocomplete Nature Documentaries. You can even do "cd N" and then Tab if there is only one file starting with N.
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Feb 19, 2008, 10:05 AM
 
Yeah, auto-complete is the way to go.

-t
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2