How to Setup and Manage Symlinks on Ubuntu Linux

|

|

This tutorial explains how to create and manage symlinks on Ubuntu Linux systems. Symlinks are file references, which let developers avoid file restructuring. The tutorial demonstrates the use of the ‘ln’ command to create a symlink and the ‘symlinks -v’ command to find symlinks in a directory.

This brief tutorial shows students and new users how to use Ubuntu Linux systems to set up and manage symlinks.

For those who don’t know, symlinks are files that link to other files—also known as weak links because they’re only links to the original files. If these links are deleted, the original files won’t be impacted since they’re only link references to them.

There’s also a hard link that functions more as copies of the files they reference than just literal links. In most instances, hard links are avoided since they copy original files and may not be suitable since you duplicate them.

Symlinks are handy in many ways. Instead of restructuring the underlying filesystems to support applications and other services, developers can use symlinks without moving files around or changing file structure.

Symlinks only work if they point to the existing files and spell out a clear path to the files they’re referencing. If the original files are deleted or moved, these symlinks will not function.

To set symlinks in Ubuntu, follow the steps below:

Create Symlinks in Ubuntu

To create a symlink in Ubuntu, install the symlink tool. By default, it should be. If not, run the commands below:

sudo apt install symlinks

After installing the symlinks tool, you can run the commands below to create a symlink.

ln -s original-file.txt linkname
  • ln ==> command to create a symlink
  • -s ==> command option which represents symlink
  • original-file.txt ==> the original file
  • linkname ==> the link name that points to the original file

That’s how one creates a simple symlink to files.

Find Symlinks

One can use the symlinks command to find symlink references in a given directory. However, the command may not be installed by default on Ubuntu.

Run the commands below to install symlinks.

sudo apt install symlinks

Now that symlinks are installed, use the commands below to search for symlinks.

You run the commands below if you want to search for all symlinks in a particular directory.

symlinks -v directory

The commands above will display all symlinks in the specified directory.

If you want to search for all symlinks in a particular directory recursively, you use the -r command option.

symlinks -vr directory

That should help you find symlinks in a specified directory.

That should do it!

Congratulations! You have learned how to create and search symlinks and references on Ubuntu.

You may also like the post below:

Like this:



One response to “How to Setup and Manage Symlinks on Ubuntu Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *

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