Which common characters are illegal in Unix and Windows filesystems?
772
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?
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?
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.
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.
It really depends on the filesystem, but most of the Unix filesystems allow any byte except NULL and /. NTFS allows all except NULL and \ / : * ? " < > |.
* 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.
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.
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.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 *?
*
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.