[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: Filenames with spaces in them



On Fri, 28 Aug 1998 Ted.Harding@nessie.mcc.ac.uk wrote:

> On 28-Aug-98 Tomt wrote:
> >       I have some files I've transfered from my Windows NT machine and
> > they have several spaces in them like
> > This is a Test.txt
> > 
> > How does linux treat spaces I'm tried the filename listed above and a
> > couple of other variants?
> 
> If such a name is read from a directory entry (e.g. you do "ls" on the
> directory they are in) then they will be read out as they are, spaces
> included.
> 
> If you need to use the name in a command, then you must shield it from
> the shell (which will treat the spaces as separating the name into
> distinct arguments "This" "is" "a" "Test.txt").
> 
> Depending on what you are doing, putting it in quotes will probably be
> sufficient at the top level. The shell will strip the quotes and take
> their contents as one item. If you have a shell within a shell then you
> have to take extra precautions. One of the best things you can do with
> such filenames is to rename them immediately:
> 
>    mv "This is a Test.txt" This_is_a_Test.txt
> 
> Then your worries are over.

Good old \ works too... bash filename completion uses them:

This\ is\ a\ Test.txt

Voila!

                       Michael Beattie (mickyb@es.co.nz)

               PGP Key available, reply with "pgpkey" as subject.
 -----------------------------------------------------------------------------
                    COFFEE AND DONUTS: Unitarian communion.
 -----------------------------------------------------------------------------
                Debian GNU/Linux....  Ooohh You are missing out!



Reply to: