Today I found myself using the readlink
command, and it occurred to me that many people might not be aware of it. Here is what the man page says it does
readlink – print resolved symbolic links or canonical file names
If you work on shared filesystems with other people, such as on a large computing cluster, or use a setup which has the same directory structure as other colleagues, you might want to share a path to a file. This is where readlink comes in handy. Let’s say I want to share the absolute path to a file in my present working directory. All I have to do is
readlink -e <path_to_file>
The -e
option is quite important. Without it, you get a relative path, instead of the absolute path. The -e
option follows all symbolic links and gives the canonical file path. Following the symbolic links was very important at my last job, in which we had shared drives which might be mounted at different locations on different servers. For example, we might have a drive like /abc123/work
, which on server A was mounted at /users/work
and on server B it was mounted at /data/users/work
for some reason. If I shared a path with a colleagues as /users/work/path/to/my/file
– they might get a file not found error if they were working on server B. But if I shared the path to /abc123/work/path/to/my/file
then they will always get the right file.