NUL
and /
has their designated system functions. Other characters does not.
That is the basics of it – the rest is opinions, speculations and history. Heard, read etc. and only included as a filler not a debate or argument:
- By forbidding certain characters you open up for complexity in the file system itself, which is the same as compromising it.
- What about which bytes constitute as a newline on various systems?
<CR>
vs <LF>
etc.
- What if a remote system decides to create a file with newline on a NFS?
- What if the filename get corrupted whilst the file contents is intact?
- What if an application encode information in the filename?
And on it goes
- Is it the systems job to fix bugs in user software?
- Should a system, on it's root level, protect users from themselves?
- Should the way the various shells are implemented internally govern a decision as to what file names are considered legal?
The basic operating system doesn't set limitations. Information to and from the system is byte streams. If a byte does not have a special meaning, don't create overhead by adding checks that should be handled in user space.
Anyhow, the biggest issue would most likely be the rather long history where newline, and other control characters, have been allowed.
Another case is what to forbid. You mention newline, but in discussions from the stone-age of UNIX, this has been debated, then also including other characters. Should *
be forbidden? What about filenames starting with -
? What about DEL
and ESC
? Should all control characters be forbidden? And so on and so forth.
I can unfortunately not recall any quotes on this topic by the founding fathers or code maintainers.
Be conservative in what you send, be liberal in what you accept
. Accepting everything gives the most flexibility to the user, future developers, applications and so on. – Zoredache Oct 04 '13 at 04:49\n
in filenames leads to more fragile scripts as most shell programmers even find dealing with spaces in filenames to be difficult and most of the reset only know aboutfind ... -print0
andxargs -0
(and don't realise, e.g., you can tell bash's built-inread
to use NUL as a delimiter with-d $'\0'
, or that many GNU tools have-0
,-z
or-Z
options for handling NUL-terminated stdin) – cas Oct 04 '13 at 06:02\n
in their filenames. – cas Oct 04 '13 at 06:06\0
and/
but my question is why not\n
? Is there ever a legitimate reason to have\n
in a file name? – terdon Oct 04 '13 at 14:43