@methyl: While spaces are obviously not, hyphens
are recommended by the Unix standard except as first character.
@guest115:
Unix kernels do not make any limitations in filenames outside two forbidden characters,
/ and
null i.e. \0 and two reserved filenames:
. and
...
File systems, especially non Unix native ones, might be stricter, even when used on Unix.
For portability, POSIX recommends restricting filenames to the portable filename character set, i.e. uppercase and lowercase a-z, digits, dot, hyphen and underscore.
There are no specific recommendations in Unix about whether using hyphens or underscores as a separator. Files with embedded spaces are on the other hand not recommended but supported anyway. They just need proper quoting/escaping when used in the command line. Hyphens pose no problem outside when they are the first character of a file, in which case some tricks are usually required depending on the command used.
I just checked on a Solaris 11 fresh install and got these statistics analyzing 168522 filenames:
- 27.57% contains at least an hyphen
- 23.13% contains at least an underscore
- 4.50% contains both an hyphen and an underscore
- 0.00% contains a space character (not a single file)
Other statistics that might be interesting:
- 2.34% are plain numbers
- 11.89% are only composed of lowercase characters & optionally digits
- 0.71% are only composed of uppercase characters & optionally digits
- 22.87% have no extension
- 94.53% comply with the POSIX portable filename character set: A-Z a-z 0-9 . - _
On this system at least, there is a slight preference for hyphens compared to underscores (I expected the opposite) but both are very common anyway, more than half of the files use at least one of these separators.