4.13. Context-Dependent Path Names


Context-Dependent Path Names (CDPNs) allow symbolic links to be created that point to variable destination files or directories. The variables are resolved to real files or directories each time an application follows the link. The resolved value of the link depends on the node or user following the link.
CDPN variables can be used in any path name, not just with symbolic links. However, the CDPN variable name cannot be combined with other characters to form an actual directory or file name. The CDPN variable must be used alone as one segment of a complete path.

Usage

For a Normal Symbolic Link
ln -s Target LinkName
Target
Specifies an existing file or directory on a file system.
LinkName
Specifies a name to represent the real file or directory on the other end of the link.
For a Variable Symbolic Link
ln -s Variable LinkName
Variable
Specifies a special reserved name from a list of values (refer to Table 4.5, “CDPN Variable Values”) to represent one of multiple existing files or directories. This string is not the name of an actual file or directory itself. (The real files or directories must be created in a separate step using names that correlate with the type of variable used.)
LinkName
Specifies a name that will be seen and used by applications and will be followed to get to one of the multiple real files or directories. When LinkName is followed, the destination depends on the type of variable and the node or user doing the following.
Table 4.5. CDPN Variable Values
Variable Description
@hostname This variable resolves to a real file or directory named with the hostname string produced by the output of the following command: echo `uname -n`
@mach This variable resolves to a real file or directory name with the machine-type string produced by the output of the following command: echo `uname -m`
@os This variable resolves to a real file or directory named with the operating-system name string produced by the output of the following command: echo `uname -s`
@sys This variable resolves to a real file or directory named with the combined machine type and OS release strings produced by the output of the following command: echo `uname -m`_`uname -s`
@uid This variable resolves to a real file or directory named with the user ID string produced by the output of the following command: echo `id -u`
@gid This variable resolves to a real file or directory named with the group ID string produced by the output of the following command: echo `id -g`

Example

In this example, there are three nodes with hostnames n01, n02 and n03. Applications on each node uses directory /gfs/log/, but the administrator wants these directories to be separate for each node. To do this, no actual log directory is created; instead, an @hostname CDPN link is created with the name log. Individual directories /gfs/n01/, /gfs/n02/, and /gfs/n03/ are created that will be the actual directories used when each node references /gfs/log/.
n01# cd /gfs
n01# mkdir n01 n02 n03
n01# ln -s @hostname log

n01# ls -l /gfs 
lrwxrwxrwx 1 root root 9 Apr 25 14:04 log -> @hostname/ 
drwxr-xr-x 2 root root 3864 Apr 25 14:05 n01/ 
drwxr-xr-x 2 root root 3864 Apr 25 14:06 n02/ 
drwxr-xr-x 2 root root 3864 Apr 25 14:06 n03/ 

n01# touch /gfs/log/fileA 
n02# touch /gfs/log/fileB
n03# touch /gfs/log/fileC

n01# ls /gfs/log/ 
fileA 
n02# ls /gfs/log/ 
fileB 
n03# ls /gfs/log/
fileC
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.