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?

  • 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, 2009 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.

  • 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, 2011 at 18:35
  • 2
    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.) Oct 5, 2012 at 21:07
  • Your example being file/dir/what-ever rather than file/dir/what ever also proves the point. Dec 15, 2021 at 16:02

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.)

  • 11
    +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. Aug 25, 2009 at 13:04
  • 5
    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, 2010 at 17:05
  • 1
    Is this real? In 2018 this happens?
    – Chris Calo
    Feb 23, 2018 at 13:01
  • @ChrisCalo You might notice that this answer was given in 2009, not 2018. But, yes, this still happens in 2018. Possibly less often, now that most rookie developers use frameworks to build websites rather than doing everything from scratch, but it's still an issue.
    – Stobor
    Mar 4, 2018 at 13:35
  • @ChrisCalo Yes, I've seen this with files downloaded from Apple's Developer site. 😒
    – endolith
    Jan 17, 2022 at 19:04

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.


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


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.


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.


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.

  • 2
    Lazy Word users ...
    – SamB
    Jan 28, 2012 at 1:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .