I've just encounter the following question in Unix Programming Environment, the Kernighan and Pike's classic book on Unix (I found the below text on p. 79 of year 1984 edition, ISBN:0-13-937699-2):

Exercise 3-6. (Trick question) How do you get a / into a filename (i.e., a / that doesn't separate components of the path?

I'be been working with Linux for years, both as end-user and programmer, but I cannot answer this question. There is no way to put slashes in filenames, it's absolutely forbidden by the kernel. You can patch your filesystem via block device access, or use similarly-looking characters from the Unicode, but those aren't solutions.

I understand that Linux ≠ Unix, but the same principle should apply, since the system has to be able to unambiguously extract directory hierarchy from paths.

Does somebody know, what exactly Kernighan and Pike thought about when asking this questions? What was the supposed answer? What exactly is the 'trick'? Or maybe original Unix system simply allowed to escape this slash somehow?


I contacted Brian Kernighan about the question and that's what he replied:

The answer is (or was) “You can't.”

Hence, Timothy Martin was right and gets the green tick.


3 Answers 3


Perhaps the answer is the same as part of the answer in this trick question:
How do you get down off an elephant? You don't. You get it from a goose.

From "The Practice of Programming" by Brian W. Kernighan and Rob Pike, Ch. 6, pg. 158:

When Steve Bourne was writing his Unix shell (which came to be known as the Bourne shell), he made a directory of 254 files with one-character names, one for each byte value except '\0' and slash, the two characters that cannot appear in Unix file names.

  • 4
    Thank you for teaching me that joke. It can, probably, serve as an English fluency test (which I've just failed). Apr 19, 2017 at 20:01
  • You were right. See UPD. May 8, 2018 at 21:08
  • 1
    @firegurafiku explain Joke.
    – user232326
    May 9, 2018 at 9:18

I've done this. This was on a UNIX system running on a PDP-11 sometime around 1980. I created a file called "WhatXNow?". I then used a binary file "editor" to edit the disk device and change the "X" to a "/" in the inode (with the file system unmounted).

The victim never figured out how to remove it.

Edit: whoops, Barmar is right, I failed to see the line in there about not patching the device. And yes, it was the directory I edited, not the inode. It's been a while :-)

  • 1
    Filenames aren't in the inode, they're in the directory special file.
    – Barmar
    Apr 19, 2017 at 18:58
  • 1
    I suspect fsck would have removed it.
    – Barmar
    Apr 19, 2017 at 18:58
  • 1
    The question says You can patch your filesystem via block device access, or use similarly-looking characters from the Unicode, but those aren't solutions. Isn't that what you're describing in your answer?
    – Barmar
    Apr 19, 2017 at 18:59
  • @Barmar: Hmm, maybe I'm overthinking the question and patching filesystem is the solution which was meant? I don't know. Apr 19, 2017 at 19:50
  • I bet this was the answer. I remember when you could read directories. Maybe ages ago root could write them.
    – Joshua
    May 7, 2017 at 1:08

Any scenario where/ (more precisely, a byte—not a character—with value 0x2f; nearly all Unix kernels are intentionally oblivious to character encoding) finds its way into a directory entry, without the raw disk blocks having been manipulated by hand, is unquestionably a bug in the kernel.

Such bugs do happen from time to time. One case I remember reading the patch notes for, is that some 1990s-era iterations of … I want to say Solaris, but that could be wrong … offered a server for the AppleTalk Filing Protocol (AFP), which was classic MacOS's equivalent of NFS. The trouble was, on classic MacOS you're perfectly allowed to put / in a pathname component; the directory separator is : instead. The AFP server was supposed to do the moral equivalent of tr :/ /: when mapping pathnames submitted by clients onto files on its disk, but they missed a couple code paths, and because the server was implemented inside the kernel, it could actually write out bad directory entries.

(See comp.unix FAQ #2.2, the subsection beginning "What if the filename has a '/' in it?", for a longer version of the above.)

You must log in to answer this question.

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