What's a "canonical path"?

Metafaniel picture Metafaniel · Aug 23, 2012 · Viewed 57.9k times · Source

So, an absolute path it's 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 it's a route to a file or location which it's 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 there are canonicalized files too! All I know it's CANONICAL means something like "according to the rules" or something.

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

Answer

Kerrek SB picture Kerrek SB · Aug 23, 2012

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.)