What is the technical term for current (.) and parent (..) directory?

20

1

I got a function that checks whether the passed in file name is . or ... But I don't know how to name it properly. Something like IsCurrentOrParentDirectory() is ambiguous, since the function takes a file name and not a full path. (Intuitively a fellow programmer would expect passing /usr/ while I'm in /usr/ would return true, while this is actually not the case.)

Is there a technical term for these directory entries? If there is one, what is it?

Max Truxa

Posted 2014-07-23T06:44:12.157

Reputation: 303

1. and .. are NOT filenames at all, but folders. Why don't you just check if the input is a valid file (type according to stat() is IF_REG) ? P.S. This is probably more suited to StackOverflow – Tonny – 2014-07-23T09:52:24.357

7@Tonny . and .. are file names according to the POSIX standard. See my quote below. I'd say it's fine here as it's about general computing concepts. – slhck – 2014-07-23T12:00:54.747

I have to admit that my wording was ambiguous again. The function takes a single file or directory name (foo.bar, foo, ...) but not a path (foo/bar, /foo/, ...). But since directories, links, etc are files too, I will leave it like that. – Max Truxa – 2014-07-23T17:53:37.293

@slhck POSIX calls it a file, but does that for ANY file-system object. File in POSIX terminology should usually be read as an abbreviation of "file system object". In early Unix and it's derivates all FSO's where indeed really files, but that is not true for some modern implementations and certainly not for non-Unix, but POSIX compliant Operating Systems (Windows NT as most obvious example). -- I probably should have written "is a regular file" instead of "valid file" in my comment, but the comment of Max Truxa makes it a moot point anyway. – Tonny – 2014-07-23T21:56:00.863

Answers

23

From the POSIX standard:

The special filename dot shall refer to the directory specified by its predecessor. The special filename dot-dot shall refer to the parent directory of its predecessor directory. As a special case, in the root directory, dot-dot may refer to the root directory itself.

So, really, if you want to check whether the filename is . or .. you would have to call it IsDotOrDotDot(), or, using the POSIX terminology of pathname resolution, IsPredecessorOrParentOfPredecessor(), or maybe even PointsToPredecessorOrParentOfPrecedessor() … you get the idea. The problem is that the latter terminology only makes sense when looking at full pathnames. But nobody would understand that anyway.

Considering that . and .. are valid filenames (just interpreted differently), you should just stick to what you have, relying on the meaning rather than how they are called internally.

slhck

Posted 2014-07-23T06:44:12.157

Reputation: 182 472

Is .bash_history dot or not dot? I'm not sure if that function name is more descriptive than the open the OP proposed. – Jens Erat – 2014-07-23T07:01:16.007

@JensErat That's irrelevant to the problem. The question was whether the filename component was . or .., and not whether it just started with a .. Of course the OP's function name is more descriptive; I was just pointing him to how it's technically referred to. – slhck – 2014-07-23T07:19:11.440

2Sure it is, but IsDotOrDotDot() says pretty much nothing about what the function is doing at all. – Jens Erat – 2014-07-23T07:22:29.923

"predecessor" refers to the path element immediately before it in the path specification. If you are just looking at the names of entries in a directory, "current" or "parent" is better terminology. – Simon Richter – 2014-07-23T11:56:12.077

2@JensErat I would use IsDotOrDotDot. Anyone knowledgeable with filesystem concepts would instantly understand it. It is debatable whether .bash_history is “dot” because no context is provided then for the meaning of “dot”, but it is definitely NOT “dot or dot dot”. – kinokijuf – 2014-07-23T14:46:18.963

@JensErat Quick check: Are you reading it the same as I was for a moment? IsDotOrDotDot is not IsDotOrNotDot. For the second, I agree, I'd expected it to be true for dot files. For the first, if I read the letters as they are there, it makes sense. That said, I very much dislike the repetition in the name... – Izkata – 2014-07-23T15:13:41.233

Why not two functions to improve readability? IsDot() and IsDotDot(). Plus then you can check specifically for one or the other if you needed to. – Kai – 2014-07-24T09:22:50.507

4

. and .. are usually used to describe relative paths vs. absolute ones like /usr. I'd use this difference and declare the function as IsRelativeCurrentOrParentDirectory().

Be aware the dot-references may occur anywhere in the path. What about /usr/local/..?

Jens Erat

Posted 2014-07-23T06:44:12.157

Reputation: 14 141

I failed to point out that the function does only take a file name and not a full path. I updated the question accordingly. – Max Truxa – 2014-07-23T07:34:41.257

2

The POSIX Standard, which slhck♦ usefully quoted, says,

The special filename dot shall refer to ….  The special filename dot-dot shall refer to ….

(emphasis added).  So, while it’s not exactly technical, it looks like “special filename” just might be the official name.  Your users would probably understand it if you called your function any of the following: IsSpecialDirectory(), IsSpecialFilename(), or simply IsSpecialName().

Or you could go with IsStandardDirectory(), IsStandardFilename(), or IsStandardName().  This follows the Unix naming convention (standard input, standard output) for things that are established for you automatically (in this case, by mkfs and mkdir).  IsAutomatic…() or IsDefault…(), on the other hand, probably are not intuitive enough.

Scott

Posted 2014-07-23T06:44:12.157

Reputation: 17 653

Actually the first name I took was IsMagicDirectory() so that's pretty close to that, but I think your wording is much more intuitive and appropriate (especially since it uses established naming conventions). Using IsSpecialFileName would even make it clear that the function does not receive a path but a single file (or directory, link, etc) name. – Max Truxa – 2014-07-24T06:58:59.143

Good suggestion. "Special" however would probably also include links, FIFOs, etc., right? – slhck – 2014-07-24T09:44:58.263

@slhck: Yes, devices (e.g., disks and ttys) are called “special files”. And, yes, the term could be loosely applied to symbolic links, FIFOs, and other exotic denizens of the file system – any type of file (i-node) other than a “regular file”. (Yes, directories fall into this bucket, too.) So IsSpecialFile() would have been a bad suggestion. But I didn’t suggest that; I suggested IsSpecialFilename(). While the names sda1, console, kmem, myfifo and urandom are suggestive, they are not reserved and are not inherently special. But . and .. are inherently special *filenames*. – Scott – 2014-07-24T16:39:13.923

1

The only term I know of from the *nix world is CWD for Current Working Directory. That is actually quite often used. See, for example /proc/$$/cwd which is a link to the directory you run the command from.

I don't know of any standard name for .. apart from dot-dot and as @slhck pointed out that's not a good choice.

terdon

Posted 2014-07-23T06:44:12.157

Reputation: 45 216

0

Posix is pretty ambiguous on speaking about parent-child directory relationships. As others have said, ./.. isn't helpful while talking or communicating with other humans.

File structures can be thought about as a tree data structure. Here, generally "parent" and "child" or "daughter" are sufficient to convey meaning. You'll see data structure textbooks carry this convention

Alternatively, it seems like trees can be talked about as "up" and "down" the tree. By convention, "up" means closer to the root directory, and "down" refers to the child(ren).

I think either IsCurrentOrUp() or IsCurrentOrParent() can be argued to be good practice for naming functions.

CodeOcelot

Posted 2014-07-23T06:44:12.157

Reputation: 101