UNIX tip of the day: readlink

pexels-photo-66100

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.

Join 165 other subscribers

archives

  • 2024 (10)
  • 2023 (8)
  • 2022 (15)
  • 2021 (19)
  • 2020 (1)
  • 2019 (1)
  • 2018 (2)
  • 2017 (1)
  • 2016 (2)
  • 2015 (5)
  • 2014 (5)
  • 2013 (2)
  • 2011 (7)
  • 2010 (10)
  • 2009 (50)
  • 2008 (28)
  • 2007 (31)
  • 2006 (8)

Category