VPS

How to Create Symbolic Links in Linux

Learning Linux symbolic commands is a great way of improving your potential 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.

What are Linux 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.

These links are stored in the mainframe, so even if the original file is deleted, you’ll have a backup for most of the  important files. Symbolic links help create invalid link pathways to store pieces of information as per the requirement of the user.

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.

How to Create Symbolic Links in Linux?

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

Create Symbolik Link in Linux for Files

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.

Create Symbolic Link in Linux for Folders

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

How to Change or Remove Symbolic Link in Linux?

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

Wrapping up

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!

About the author

Edward S.

Edward is Hostinger's copywriter. He's an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward's goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in VPS
How to Disable Selinux on CentOS 7
Close