Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a "canonical path"?

So, an absolute path is a way to get to a certain file or location describing the full route to it, the full path, and it's OS dependent (the absolute paths for Windows and Linux, for example, are different). A relative path, on the other hand, is a route to a file or location which is described from the current location .. (two dots) indicating a superior level in the directories tree. That has been clear to me for several years now.

When searching I've even seen that there are canonicalized files too! All I know is that CANONICAL means something like "according to the rules" or something.

Can somebody enlighten me in therms of theory about canonical stuff?

like image 917
Metafaniel Avatar asked Aug 23 '12 21:08

Metafaniel


People also ask

What is a canonical path?

The canonical path is always an absolute and unique path. If String pathname is used to create a file object, it simply returns the pathname. This method first converts this pathname to absolute form if needed. To do that it will invoke the getAbsolutePath() Method and then maps it to its unique form.

What is canonical and absolute path?

Absolute path defines a path from the root of the file system e.g. C:\\ or D:\\ in Windows and from / in UNIX based operating systems e.g. Linux or Solaris. The canonical path is a little bit tricky because all canonical path is absolute, but vice-versa is not true.

What is canonical path in Android?

CanonicalFilePath is the pathname of a file object. If we create the file object using an abstract path, the canonical file path is the same as the abstract file path. If we create the file object using a relative path, the canonical file path is the path that is both the shortest absolute and unique path.

What are the 2 types of paths in Linux?

There are two basic types of paths: relative paths and absolute paths. A relative path is the location of a file relative to the current directory. The current directory is the directory in which the user is currently working.


1 Answers

The whole point of making anything "canonical" is so that you can compare two things. For example, both ../../here/bar/x and ./test/../../bar/x may refer to the same location, but you can't do a textual comparison on the two paths. However, if you turn them into their canonical representation, they both become ../bar/x, and we see that they actually refer to the same thing.

In short, it is often the case that you have many ways of referring to one thing, and in that case you may be able to define a canonical representation which is unique and which allows you to get a handle on col­lections of such things.

(If you're looking for more examples, all of mathematics is full of "canonical" constructions for all sorts of objects, and very much with the same purpose in mind. Maybe this Wikipedia article can provide some ad­ditional directions.)

like image 145
Kerrek SB Avatar answered Sep 20 '22 09:09

Kerrek SB