Spaces (and other characters) in filenames

Kelly L. Fulks kfulks at knology.net
Wed Aug 23 12:24:42 UTC 2006


Dotan Cohen wrote:
> I must come to a solution that will satisfy the wife's need of spaces
> in filenames and linux's hate of the practice. Is there a simple
> command that I can run that will convert all the spaces in filenames
> in recursive directories (including the directories) to an underscore,
> and another command that will recovert all the underscores to spaces?
> 
> I also need to know what characters are valid in filenames. I know
> that [a-z][A-Z][0-9] are valid, but what about comma, single- and
> double-quote, grerater- and lesser- than signs, etc? What is valid? Is
> there a command that I can run that will convert all the invalid
> characters in recursive directories to something valid, such as a
> minus sign?
> 
> I know that I really do need to learn bash to answer these questions
> on my own. I intend to do that, in the little spare time that I have,
> but in the meantime I very much appreciate everybody's patience with
> my ignorance. Computer major I am not!
> 
> Dotan Cohen
> http://what-is-what.com
> 

I was unaware that Linux hates the practice of using spaces in
filenames.  I guess those directories and files laying around for the
past 13  years on my various Linux systems with spaces in them aren't
really there:-)  If you are attempting to access a file with spaces in
its name from the command line, then there are special ways of doing so,
but from Konqueror or most other GUI apps, it is not a problem at all
from my experience.

Also to the best of my knowledge, the filesystem itself doesn't have any
major rules as to filenames except length.  You can use almost any
character in a filename.  However, the same thing applies to accessing
the files from the command line.  Certain characters are reserved by the
Unix/Linux shells and to use these characters, you must escape them on
the command line.  So if you want to use a filename of "a b", from the
command line you would have to type "a\ b" to access it (or you can
enclose it in quotes).  If you want to use a filename of "a>b", then
from the command line you would have to type "a\>b" (or you can enclose
it in quotes).

-- 
Kelly L. Fulks
Home Account
near Huntsville, AL




More information about the kubuntu-users mailing list