13

I am looking for a character in Unix and Windows filesystems that is not allowed in file and directory names and I was wondering if there is such a character. I have noticed that * and % are allowed?

1
  • Please change either the title or the question so that they are both about the same thing. Mar 2, 2011 at 11:22

4 Answers 4

16

There is no such thing as a "Unix" filesystem. Nor a "Windows" filesystem come to that. Do you mean NTFS, FAT16, FAT32, ext2, ext3, ext4, etc. Each have their own limitations on valid characters in names.

Also, your question title and question refer to two totally different concepts? Do you want to know about the subset of legal characters, or do you want to know what wildcard characters can be used in both systems?

http://en.wikipedia.org/wiki/Ext3 states "all bytes except NULL and '/'" are allowed in filenames.

http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx describes the generic case for valid filenames "regardless of the filesystem". In particular, the following characters are reserved < > : " / \ | ? *

Windows also places restrictions on not using device names for files: CON, PRN, AUX, NUL, COM1, COM2, COM3, etc.

Most commands in Windows and Unix based operating systems accept * as a wildcard. Windows accepts % as a single char wildcards, whereas shells for Unix systems use ? as single char wildcard.

4
  • 2
    Technically, the device name restriction is just in the Win32 subsystem. You can create files containing those strings using POSIX on Windows, like in Cygwin.
    – mfinni
    Mar 2, 2011 at 14:54
  • Ooh, good points.
    – mfinni
    Mar 3, 2011 at 14:46
  • "Most commands in Windows and Unix based operating systems accept * as a wildcard. Windows accepts % as a single char wildcards, whereas shells for Unix systems use ? as single char wildcard." - those are expanded in shell not the process. Shell might expose it's own syntax and restrictions - and usually means of escaping. It's possible to create in bash file containing them by for example touch '*'. If this is good idea is separate topic... Oct 10, 2017 at 18:46
  • "Windows accepts % as a single char wildcards..." I am sorry, but I believe this must be a typo. Windows accepts '?' as a single char wildcard, and always has since Win 3.x and DOS. The character '%' has never been used as a wildcard character in globbing syntax that I am aware of in 30 years of usage.
    – raccoon
    Feb 17, 2022 at 16:26
8

Most filesystems are fairly permissive: for example, all NTFS, extN, btrfs, XFS and ReiserFS allow everything except 1) the null byte and 2) the slash /.

The operating system may have its own restrictions. In particular, the Win320 API disallows * ? as wildcards, \ / as path separators, : as stream separator, and < > | " for no good reason1. Also disallowed are ASCII control characters (the 0x00-0x1F range).


In Unix, wildcard expansion is done by the shell and by the glob() function. In Windows, it's the job of the filesystem driver, which is why * and ? cannot be used in file names.


0 I have no information about the POSIX and OS/2 APIs offered by Windows.

1 They are special in the command line shell (cmd.exe), but it surely could (and in fact does) handle escaping like Unix shells do.

5

It really depends on the filesystem, but most of the Unix filesystems allow any byte except NULL and /. NTFS allows all except NULL and \ / : * ? " < > |.

There is an extremely helpful comparison chart on Wikipedia: http://en.wikipedia.org/wiki/Comparison_of_file_systems

That said, almost all shells recognize * as a wildcard first and a character in a filename only when escaped. Why wouldn't use use *?

2

* should work as a wildcard in both, but it's the shell or the invoked command that expands these things, rather than the filesystem itself. Bash, for instance will expand * to a space separated list of files in the current folder.

I don't think either filesystem expressly forbids any character. It's quite possible to create filenames on ext2 or NTFS with names like *&(. Windows GUI might not let you, but you can do it in Cygwin, since the underlying filesystem allows for it.

You must log in to answer this question.

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