Click to See Complete Forum and Search --> : Directory help


Bluehose
12-16-2007, 11:21 AM
I am using Linux to copy the contents of one directory to another and am having difficulties. In DOS speak, I am trying to copy the contents of a subdirectory from one disk to another disk. I have figured out the cp command in Linux, however, I've run across a problem with directory naming conventions.

When I type in ls to view the contents of the root of my first disk (/mnt/disk/sda1), I get the subdirectories in blue and the files in green (right?). I want to use cd to look at the contents of a subdirectory called Documents and Settings. I know that Linux is case sensitive, but every time I try to go to Documents and Settings I get the message that no such directory exists. I can see it when I use the ls command, but I assume the spaces between words is a problem. My question is, how do I view the files and subdirectories under a subdirectory that has spaces in the name? I tried underlines between spaces but that didn't work.

Thanks in advance from a very very green Linux user!

saikee
12-16-2007, 12:05 PM
Bluehose

Welcome to Justlinux


Use the complete facility of the tab key.

In Linux if you type part of the directory and then hit the tab key instead of return the kernel will respond with the choices that match what you have already typed.

From it you learn how the space is entered in Linux for directories. Killing two bird with one stone. Give it a try.

Bluehose
12-16-2007, 12:42 PM
Thank you! I'll give that a shot.

bwkaz
12-16-2007, 03:31 PM
Bash's tab completion will do this for you, but if (for some crazy reason) you don't want to use tab completion, you can do it manually in one of three ways.

First, you could escape the spaces, so they don't get treated as word separators (this is what makes the cd command fail). The escape character is the backslash, so something like cd Documents\ and\ Settings would work. (This is the method that the tab completion will probably use, but see below also.)

Second, you could put the directory name in quotes. In this case, either double or single quotes would work fine (just make sure you match them). If you start a word with a quote and then try to use tab completion, it will also end the quote for you when it thinks you need to end the word (and inside quotes, you don't need to escape the space, so this is the one case where tab completion won't add backslashes). So cd "Documents and Settings" or cd 'Documents and Settings' would work.

You could also change the special $IFS variable -- it controls which characters the shell treats as word separators. The problem with that option is the space after "cd" and before the directory name -- it wouldn't be treated as a word separator either. But I'll list it, just to be complete. :)