Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Somebody I know expressed irritation today regarding those of us who tend not to use spaces in our filenames, e.g. NamingThingsLikeThis.txt -- despite most modern operating systems supporting spaces in filenames.

Are there technical reasons that it's still common to see file names without (appropriate) spaces? If so, what are these technical reasons that spaces in filenames are avoided or discouraged, and in what circumstances are they relevant?

The most obvious reason I could think of, and why I typically avoid it, are the extra quotes required on the command line when dealing with such files. Are there any other significant technical reasons?

share|improve this question

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

    
Like you said, they are a lot easier to deal with on the command line. And for programming is I am not sure if it is even possible or feasible to use spaces in filenames. –  Alvin Row Aug 25 '09 at 0:34

5 Answers 5

Whitespace characters in filenames can be a right royal pain in the proverbial in many contexts on the command line, and in scripts, where you have to be careful to make sure they are properly escaped so don't look like separators to the commands you are running.

It is just safer not to have them there, even if you are sure the file/dir/what-ever is never going to be used in such a context.

That, and old habits die hard.

share|improve this answer
    
They're also a right royal pain to deal with then you have to compose paths and modify them. Making sure that the components are unquoted and unescaped for modification before re-escaping/re-quoting, especially if pieces get sent off to other bits of code to be manipulated. –  afrazier Mar 16 '11 at 18:35
1  
If you think spaces are bad, try dealing with files with newlines ('\n') in their names. (Unix-like systems actually allow this; Windows generally, or at least makes it difficult.) –  Keith Thompson Oct 5 '12 at 21:07

Sometimes, spaces can present a problem when dealing on the command line, or when using older OS's, or when writing programs which will be compiled on different OS's, or when ... there are many reasons which can present problematic, and I don't really feel it is such a trouble to write the file as: file-without-blanks.txt or *file_without_blanks.txt*. I prefer the dask because the underscore can sometimes become invisible when dealing with, for example, underlined font.

But mostly, it is a matter of habit from the old age. Which I don't feel there are enough pro reasons to abandon.


An additional note, possibly not related, but nevertheless I'll put it here. People who name their files with spaces usually do not think much of that; the ones who don't often know a little of why it is good to avoid them in filenames.
And, we can all agree, there is nothing worse than a file which is names "Dear Sir or Madam, I'm writing you this letter to inform you of yo.doc".

Not just spaces - file length also counts for something, and IMHO, it should not be longer than, let's say, 30 characters. For long file names with spaces inside are also a blessing when recording CD's, DVD's and such which need to be read under older OS's, and in between Win and *nix plaforms.

share|improve this answer
1  
Lazy Word users ... –  SamB Jan 28 '12 at 1:46

In addition to the other answers about command line and old habits, there are also many network protocols which require special care when dealing with filenames containing spaces.

(If you've ever tried to download "Product List.pdf" from a website, and ended up with a file just called "Product", you got bitten by this, because the programmer on the other end didn't know or couldn't figure out the quoting rules for the http Content-Disposition header.)

share|improve this answer
8  
+1. HTTP for a start. Spaces in URLs (for any protocol, not just HTTP) should be escaped out to %20 or +. Confusion can arise when they are not encoded as the should be. For web pages there is a visual reason to avoid both spaces and the underscore ("_") commonly used to replace them - they may both look the same in an underlined link, so someone copying the link manually or reading it to someone may get it wrong. –  David Spillett Aug 25 '09 at 13:04
2  
One of the most annoying things about spaces needing to be encoded in URLs is the tendancy for certain software to end up keeping the spaces encoded ... –  SamB May 29 '10 at 17:05

Spaces are encoded or converted to %20 in file names on the web, which may make it harder to manage a site's assets.

Having Image 1.png and Image%201.png is confusing. It's easier to use Image001.png instead.

This really falls under the same category as escape sequences for command line.

share|improve this answer

A lot of the reasons are historical. That doesn't mean that they don't make sense today.

Issues in Portability

When naming a file, you may also have to consider how other (file) systems will treat that file name. A character in a file name may be fine for your system, but it may be an issue for another system.

So, as long as there was the slightest possibility that you may want to be able to access the file easily from an older system, you'd pick only safe character. This may include booting into an old recovery system you kept around or the fear that recent Windows versions are still somehow based on MS-DOS.

Length

A file system may limit the length a file can have. This was even more serious during the days when MS-DOS was limited to 8.3 filenames. So, leaving out spaces enabled you to put more meaningful characters into the name.

Several other file systems also defined strict limits on their file name length. Wikipedia has a table in the article about file system comparison for those that want the details.

Reserved Characters

MS-DOS also defined the space character as a reserved character. This is due to the fact that the space character was used for padding in the FAT. Additionally, MS-DOS did not provide for an escaping system in the shell.

Command-Line Interpretation

Most command-lines I am aware of use the space character as a parameter delimiter. When neglecting to properly escape a filename, it can have dire consequences as parts of the filename can be interpreted as parameters to the application you wanted to call.

Consider the difference between

rm foo bar

and

rm "foo bar"

The WikiPedia article linked above even points out ambiguity introduced by missing to properly escape a command:

Ambiguity can be prevented either by prohibiting embedded spaces in file- and directory names in the first place (for example, by substituting them with underscores '_'), or, if supported by the command-line interpreter and the programs taking these parameters as arguments, by enclosing a name with embedded spaces between quote characters or using a escape character before the space, usually a backslash ('\'). For example

Long path/Long program name Parameter one Parameter two ...

is ambiguous (is "program name" part of the program name, or two parameters?); however

Long_path/Long_program_name Parameter_one Parameter_two ...,
LongPath/LongProgramName ParameterOne ParameterTwo ...,
"Long path/Long program name" "Parameter one" "Parameter two" ...

and Long\ path/Long\ program\ name Parameter\ one Parameter\ two ...

are not ambiguous.

Uniform Resource Locators (URL)

When trying to describe the location of a file, using a URL, spaces need to be escaped.

Characters can be unsafe for a number of reasons. The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs.

Source: RFC1738

Thus, a space has to be replaced with a %20 instead. This makes the filename part of the URL less readable and, thus, makes people avoid it in the first place.

share|improve this answer
    
Thats really good answer. It should be on top! –  Kamil Aug 3 at 0:43

protected by studiohack Mar 16 '11 at 16:36

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.