Files with empty names

A filename may not be empty. To quote the Single Unix Specification, §3.170, a filename is:

A name consisting of 1 to {NAME_MAX} bytes used to name a file. The characters composing the name may be selected from the set of all character values excluding the <slash> character and the null byte.

So, it must consist of at least 1 byte, i.e., not empty.

Not that from that definition, none of those characters need to be visible (i.e., could all be whitespace) nor do they need to be printing (could all be control characters). And if you're assuming file names are UTF-8, they need not be.


I don't think you can have a file without a name. However, you might want to handle the (rather contrived) case of a file name that consists of nothing but spaces, which are possible:

$ echo "Hi" > "          "
$ echo "Bye" > "         "
$ cat "         "
Bye
$ cat "          "
Hi

Tags:

Filenames