-3

I was reading this question and started wondering what exactly .. and . that we can see in every directory means and how I could potentially add my own ... that could mean for example parent of my parent directory or simply my home directory instead of ~ and if it is even possible to do that. I'm interested in Ubuntu but it is probably similar in every version of Linux since this feature is consistent across every platform I know.

Edit: thanks to everyone that wanted to help but I was not really interested in strictly substituting ... into ../.. but the whole concept of . and .. being shown in every application and simply was wondering what it would take to implement my own symbols available for every script/application and above examples was the easiest way to explain it since both are familiar enough for most people.

2 Answers2

1

. and .. are things the operating system implements. They might actually exist in the on-disk filesystem structure the same as every other directory, or they might be implemented specially, but that doesn't matter to the user. If you wanted to implement ... similarly, you'd need to do it in the filesystem driver (or in the general filesystem handling code of the OS). I suppose you could try with e.g. FUSE on Linux, though.

~ is a whole another matter, it's completely a user-space construct (like the concept of home directories is to begin with), one implemented commonly by the shells, but also known by some (not nearly all) other programs.

ilkkachu
  • 138,973
0

TL;DR : You must write your own shell to transfom at substitution time ... to ../...

details:

. and .. are convention used to represent actual and (mostly) upper directory. (mostly because /'s .. is .).

Those convetions are used by internal unix function like open(2) and ls(1).

In any programming langage using respectively open("./foo.txt") or open("../bar/foo.txt") (*) will (try to) open foo.txt in current dir or in adjacent bar dir.

(*) access mode omited.

ls -a will output . and .. as convention for current dir and upper dir.

~ is a convention from some shell (bash and ksh comes to my mind, but many other). bash will process with a substitution of ~ with your home path.

Note that open('~') will try to open a file who's name is '~'.

also note that touch ... and mkdir ... will create so called file and directory.

You must write your own shell to transfom at substitution time ... to ../...

Archemar
  • 31,554
  • "internal unix functions like ls(1)" -- well, for one, I'd call ls an application (or utility), as it's not usually a function called from within another program. Also I doubt many implementations of ls do much to handle .. themselves, as they can just rely on the OS (or the standard functions anyway) to deal with it. Similarly, implementing ... in the shell only would mean that most applications could not use it in the same way as ... (Which would make it similar to ~, but having .. and ... that work differently from each other might be odd.) – ilkkachu May 19 '23 at 13:35
  • thanks but I was not really interested in strictly substituting ... into ../.. but the whole concept of . and .. being shown in every application and simply was wondering what it would take to implement my own symbols available for every script/application and above examples was the easiest way to explain it since both are familiar enough for most people – Arek Kubiński May 22 '23 at 07:01