Jim's
Tutorials

Spring 2019
course
site

Unix File Link Testing

Note on links: according to this Stack Exchange answer, most Unix-like operating systems (inexplicably) create links with the source path relative to the link's path. Thus, links should always be created using absolute paths for source and link location.

Symbolic links

ln -s /path/to/source /path/to/link

Permissions

Sym links are an entirely different file system entry than a file or directory. They maintain a "full" set of permissions at all times (rwx for all users), but in reality this means very little. It should be noted that attempting to use chmod to modify the permissions of a sym link will not return an error, but also will have no effect.

Working directory

Executing a sym link that links to a non-executable file will return a permission denied error. Executing an executable file via its symlink will by default execute that file with its own directory path as the working directory, rather than the directory path of the sym link.

Hard links

ln /path/to/source /path/to/link

Permissions

Hard links are really just two completely seperate file system entries for the same data, with no indication whatsoever that they are really a link. Because permissions are stored with the file data, not with the file system entry, changing the permissions of a hard linked file will change its permissions everywhere. The owner of the file is likewise stored with the data rather than the entry, meaning the file's permissions are always relative to the same user and their groups, even when hard links are created for other users on the system.

Working directory

Hard linked executables use wherever they are executed from as the default working directory. Creating a hard link of an executable without also linking its appropriate dependencies will cause it to fail.

https://cs.marlboro.college /cours /spring2019 /jims_tutorials /guthrie /notes /linktesting
last modified Mon November 25 2024 11:27 am