PDF download Download Article
Learn how to make shortcuts to files and directories in any version of Linux
PDF download Download Article

In Linux, you can create symbolic links (symlinks) to point to other files and directories. These symlinks act as shortcuts, similar to icons on your desktop. This guide will teach you how to symlink in Linux, both to files and directories, and help you view and manage your symlinks.

Things You Should Know

  • To create a symlink to a file, use: ln -s <source_file> <link_name>
  • To symlink a directory, use: ln -s <source_directory> <link_name>
  • To see which file or directory a symlink points to, use: readlink <link_name>
Section 1 of 7:

Symlink to a File

PDF download Download Article
  1. Replace "source_file" with the full path to the file you want to link to, and "link_name" with the label you'd like to give it.
    • For example, let's say you want to add a link to /etc/httpd/conf/httpd.conf to the current directory so you can edit it without typing the full path. In this example, we'll call the link "apacheconf." To do this, run the command ln -s /etc/httpd/conf/httpd.conf apacheconf.
      • You can omit the "link_name" to keep the same name as the original file. For example, if you enter ln -s /etc/httpd/conf/httpd.conf, this creates a symlink called "httpd.conf" in the current directory.
  2. Advertisement
Section 2 of 7:

Symlink to a Directory

PDF download Download Article
  1. The command is the same as creating a symlink to a file.
    • For example, let's say you want to add a link to /var/www/html to your home directory called "website." If you're in your home directory, you'd use ln -s /var/www/html website.
    • You can also specify a full path to the link destination, e.g., ln -s /var/www/html /home/myusername/website.
    • Any permissions you apply to a directory's symlink will apply to that directory.
Section 3 of 7:

See Where a Symlink Points

PDF download Download Article
Section 4 of 7:

Overwrite a Symlink

PDF download Download Article
    • For example, let's say you have a symlink called "website" in the current directory that points to /var/www/html but should be pointing to /var/www/html2. If you used ls -n /var/www/html2 website, you'd get an error because the symlink already exists. Instead, use ls -sf /var/www/html2 website to overwrite the existing symlink.
Section 5 of 7:

Remove a Symlink

PDF download Download Article

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

  • If you omit the -s option in ln -s, you'll create a hard link instead. A hard link creates a mirror copy of the target file or directory instead of an alias.[1]
  • In most Linux graphical file managers, symlinks are marked with arrows.
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

You Might Also Like

Copy a Directory Linux Copy a Directory with the cp Command on Linux
Rename Directory Linux Rename Linux Directory in Ubuntu, Fedora, & More
Copy Files in Linux Copy Files in Linux: A Complete Guide
Create a File in a Directory in LinuxCreate a File in a Directory in Linux
Use SSHUse SSH
Run a Program from the Command Line on LinuxRun a Program from the Command Line on Linux
Share Files Between Linux Computers Using NFSEasily Share Files Between Linux Systems with NFS
Check Path in UnixCheck Path in Unix
Run Files in LinuxRun Files in Linux
Cygwin Command Cheat SheetCygwin Command Cheat Sheet
Linux How to Mount Drive Mount Drives on Linux: Command Line & GUI
CD to iCloud Drive on Mac CD to Your iCloud Drive on a Mac
Delete Read Only Files in Linux Delete Read-Only Files in Linux
Create a Link Create a Link: Easy, Step-by-Step Instructions
Advertisement

About This Article

Luigi Oppido
Reviewed by:
Computer & Tech Specialist
This article was reviewed by Luigi Oppido and by wikiHow staff writer, Nicole Levine, MFA. Luigi Oppido is the Owner and Operator of Pleasure Point Computers in Santa Cruz, California. Luigi has over 25 years of experience in general computer repair, data recovery, virus removal, and upgrades. He is also the host of the Computer Man Show! broadcasted on KSQD covering central California for over two years. This article has been viewed 16,983 times.
How helpful is this?
Co-authors: 3
Updated: December 31, 2023
Views: 16,983
Categories: Linux | File Manipulation
Thanks to all authors for creating a page that has been read 16,983 times.

Is this article up to date?

Advertisement