2

(Not that you would ever want to), is it possible to create a directory with the literal name .. or .? Under most filesystems it is a reserved name, but would it be possible on, say, XFS, JFS, or some other filesystem which permits it? If so, how?

Secondary question: if you manually modified the filesystem without mounting it, could you create a directory like that, and what would be its behaviour?

retnikt
  • 319
  • 2
    It's not a "reserved" name. Your filesystem may actually have .. and . dir entries, but the kernel won't care about them. At least on linux, cd .., test -d .., test -d . will work as expected no matter if the filesystem has such a directory entry or not. I'm not able to give you an example now, but I had created a test FUSE "nullfs " fs which implemented a single dir which returned regular files for any name, including . and .., and did not list any entries (not even . or ..), but the kernel did not care, and everything was fine. –  Nov 07 '19 at 20:45
  • 1
    To keep compat with silly tools, most fs do fake the . and .. entries when listing directories, without actually storing them -- search for emit_dots in the linux source. –  Nov 07 '19 at 20:47
  • I agree with mosvy. Also, you mention (not that you would ever want to). But since you ask the question you probably do want to... Depending on what your purpose is you could create a directory with another name but where it's rather invisible that the name is different. 2 examples: Add a space at the end, use unicode characters that are also displayed as dots but are not dots – Garo Nov 08 '19 at 00:22
  • @Garo I was just wondering. It was purely hypothetical – retnikt Nov 08 '19 at 06:57
  • 1
    @Garo even better, spike the file names with ZWJ, ZWNJ or bidi marks: mkdir /tmp/dots; perl -e 'open my $f, ">", "/tmp/dots/.$_." for map chr, 0x200c, 0x200d, 0x200e, 0x200f'; ls -a /tmp/dots. Even the infamous GNU ls quoting won't show them differently (unless you're using the C locale). –  Nov 08 '19 at 13:22
  • @mosvy can you make your comment into an answer. – ctrl-alt-delor Aug 04 '20 at 09:08

1 Answers1

0

No. Because those entries already exist in each directory. You cannot have two entries with the same name.