19

I seems like it is possible to create filenames in unix with just about any valid character.

touch \; &&
touch \\ &&
touch \" &&
touch $'\n' &&
touch $'\t' &&
touch $'\v' &&
touch $'\23' &&
touch $'\13' &&
echo "DONE!"

The only characters I have found that does not work are / and NUL:

touch /
touch $'\0'

Are there any other characters that are invalid or impossible to use in filenames?

wefwefa3
  • 1,385

1 Answers1

30

The answer is: In Unix-like systems, file names are composed of bytes, not characters. At least from the perspective of the kernel and its APIs.

A Unix-like kernel is normally neutral about any byte value but \000 (ASCII: NUL) and \057 (ASCII: slash). In Linux, there are no other restrictions at the filesystem layer, but certain FS drivers and their modes lead to the rejection of some names, usually due to the impossibility of translation. For example, one can’t create a filename with invalid UTF-8 on anything mounted with -o iocharset=utf8 (e. g. types cifs or vfat). None of DOS/Windows-compatible FSes will allow you to make \134 (ASCII: backslash) a part of a name. Or the msdos type will apply DOS restrictions concerning 8.3 names.

Ext3/ext4 isn’t known to have restrictions but aforementioned \000 and \057.

Alexis Wilke
  • 2,857
Incnis Mrsi
  • 1,988
  • 2
    also, a filename has to contain at least one character. –  Dec 30 '20 at 09:27
  • 1
    There's also the fact that case-insensitive filesystems, like msdos and its ilk, will have problems with any filenames matching already existing files with different case, when there would otherwise be no conflict. Not exactly a character-based restriction, but is a consequence of character-based rules. – ddawson Jul 20 '21 at 19:48