Say you have some file
foo/bar/baz.txt … and you want to know the path “up” from that file to the directory
foo. In this example, this would be
../... For that I’m using the following in my Makefile:
As a shell command outside of a Makefile this can look like this:
Note that this is the
realpath command from the GNU coreutils. As noted in this answer on UNIX Stack Exchange there are many different implementations of
realpath with different features.