views:

445

answers:

7

I'm not asking about general syntactic rules for file names. I mean gotchas that jump out of nowhere and bite you. For example, trying to name a file "COM<n>" on Windows?

+2  A: 

Well, for MSDOS/Windows, NUL, PRN, LPT<n> and CON. They even cause problems if used with an extension: "NUL.TXT"

James Curran
+2  A: 

A tricky Unix gotcha when you don't know:

Files which start with - or -- are legal but a pain in the butt to work with, as many command line tools think you are providing options to them.

Many of those tools have a special marker "--" to signal the end of the options:

gzip -9vf -- -mydashedfilename
Vinko Vrsalovic
+1  A: 

Unless you're touching special directories, the only illegal names on Linux are '.' and '..'. Any other name is possible, although accessing some of them from the shell requires using escape sequences.

EDIT: As Vinko Vrsalovic said, files starting with '-' and '--' are a pain from the shell, since those character sequences are interpreted by the application, not the shell.

Branan
+7  A: 

From: http://www.grouplogic.com/knowledge/index.cfm/fuseaction/view_Info/docID/111

The following characters are invalid as file or folder names on Windows using NTFS: / ? < > \ : * | " and any character you can type with the Ctrl key

In addition to the above illegal characters the caret ^ is also not permitted under Windows Operating Systems using the FAT file system.

Under Windows using the FAT file system file and folder names may be up to 255 characters long

Under Windows using the NTFS file system file and folder names may be up to 256 characters long

Under Window the length of a full path under both systems is 260 characters

In addition to these characters, the following conventions are also illegal: Placing a space at the end of the name Placing a period at the end of the name

The following file names are also reserved under Windows: com1, com2, com3, com4, com5, com6, com7, com8, com9, lpt1, lpt2, lpt3, lpt4, lpt5, lpt6, lpt7, lpt8, lpt9, con, nul, and prn

Jacob T. Nielsen
A: 

You can check out this article.

h3rald
+3  A: 

Full description of legal and illegal filenames on Windows: http://msdn.microsoft.com/en-us/library/aa365247.aspx

Adam Rosenfield
+2  A: 

The boost::filesystem Portability Guide has a lot of good info.

Trent