Updated 2021-04-26

How to Create Symlinks

Overview

  • Symlinks in Linux, also known as symbolic links, are a special type of file that points to another file or directory.
  • Basically, they are a shortcut to files that are often more convenient than accessing the original file path.
  • Example: Your research group might have a shared directory which is one level up from your project dir (/storage/coda1/p-jdoe4/0/shared vs /storage/coda1/p-jdoe4/0/gburdell3). Instead of navigating one level up, and then entering your shared directory, you would like your research directory right in your home folder. A symlink can achieve this.

Important

Always use -s to create soft links. They are much easier to work with

  • To create a symlink, use the command below
ln -s <Folder or File Name> <Link Name>
  • The ln command creates symlinks, and the -s sets the type of link to soft link
  • The first name is your folder name, the folder you want the link to point to
  • The second name is the link name. This name will show up in your current folder as the symlink. If you leave this argument as . or empty, the link will be created in the current working directory, and the link name will be identical to the folder/file you're linking to
  • All research groups have a shared directory, which will be one level up from your project directory with a path similar to:
/storage/coda1/p-jdoe4/0/shared
  • The term /shared at the end of the path might differ between groups, but the shared directory will still be one level up from the individuals project directory, and therefore not convenient to access.
  • Solution: To access this shared directory in your home directory, you must create a symlink using the command steps below:
  • First Navigate to your home directory using cd ~
  • Create the symlink with ln -s /storage/coda1/p-jdoe4/0/shared my_link_name, where /storage/coda1/p-jdoe4/0/shared is replaced with the path to your groups shared directory, and my_link_name is replaced with the name you want to call the link that shows up in your home directory
  • A link named my_link_name should appear in your home directory, which you can treat like any other folder. If you enter the directory with cd my_link_name, you should see the contents of your groups' shared directory