How to Create Linux Symlinks (Symbolic Links) for Files and Directories

How to Create Linux Symlinks (Symbolic Links) for Files and Directories

Knowing how to create a symbolic link using Linux commands is a great way of increasing your knowledge in the Linux terminal. In this tutorial, we’ll cover a few commands to learn symbolic links in a quick and easy way. Before we begin, let’s overview what are symbolic links.

Symbolic Links are not only helpful in creating shortcuts and file management in operating systems like Linux. They also serve as a way to create various locations for primary user folders, for instance, Documents, Pictures, Downloads, and much more!

Symbolic Links act like a string creating pathways for different files, folders, and directories in the computer system. They are capable of creating and storing multiple files in different places refer to one single file. Thus, increasing efficiency by locating all the specific documents in one command.

Due to the user-friendly features in Linux, even Microsoft is following it to create Symbolic Links. Symbolic links, also known as Soft links or Symlinks, are not unique to Linux but they are just like a Search option in Windows where one can search a specific file or directory in a disk by executing various commands.

Let’s look at how you can create file and folder links in Linux:

Generally, to create links use we use the ln command and the -s option to specify Symbolic links. This is the easiest way to ensure a flexible approach that allows experimenting with the language as much as possible. There is nothing hard in creating Symbolic links in Linux – you just need to follow one simple step.

ln -s [target file] [Symbolic filename]

The ln command in Linux creates links between source files and directories.

  • -s – the command for Symbolic Links.
  • [target file] – name of the existing file for which you are creating the link
  • [Symbolic filename] – name of the symbolic link.

Created links can be verified by directory listing using detailed list command:

ls -l
Linux symbolic link ownership output on Ubuntu

However, if you do not specify the [Symbolic filename], the command will automatically create a new link in the existing directory.

Creating symbolic links for folders is not difficult either. The command used to create the folder symbolic link is:

ln -s [Specific file/directory] [symlink name]

For example, to link the /user/local/downloads/logo directory to /devisers folder, use the following command:

ln -s /user/local/downloads/logo /devisers

Once a Symbolic link is created and attached to the folder /devisers, it will lead to /user/local/downloads/logo. When the user changes directory – cd – to /devisers, the system will automatically change to the specific file and write it in the command directory.

Symbolic link options are called command line switches. Here are the most common ones and their descriptions:

Command SwitchDescription
–backup[=CONTROL]backup each existing destination file
-d, -F, –directorysuperuser is allowed to attempt hard link
-f, –forceexisting destination file is removed
-I, –interactiveprompt before removing destination files
-L, –logicaldeference targets that are symbolic links
-n, –non-dereferencesymbolic links to directory are treated as files
-P, –physicalmake hard links directly to symbolic links
-r, –relativecreate symbolic links relative to link location
-s, –symbolmake symbolic links instead of hard links
-S, –suffix=SUFFIXoverride usual backup suffix
-v, –verboseprint name of each linked file

You can remove existing links attached to files or directories by the unlink or rm command. This is how you can do it with the unlink command:

unlink [symlink to remove]

Removing symbolic link using the rm command is similar to the unlink command which is as under:

rm [symlink name]

For instance:

rm simpleText


Remember, if the source is no longer in the current location, then you should delete the symbolic files to avoid creating duplicates, which might slow down your work.

Linux is a wonderful platform for creating an interactive and dynamic application, where you can experiment and innovate. A strong foundation is critical. Learn the basic of the language thoroughly to use it to its full potential. We hope this tutorial helped you improve your skills with another useful tool!

The author

Edward S.

Edward is a content editor with years of experience in IT writing, marketing, and Linux system administration. His goal is to encourage readers to establish an impactful online presence. He also really loves dogs, guitars, and everything related to space.