Questions tagged [symbolic-link]

A symbolic link or symlink is a special type of file that contains a reference to another file or directory as an absolute or relative path. For most operations, symbolic links are transparent and the read or write operations on symbolic link files are redirected to the files that symbolic link files link to.

A symbolic link, or symlink, is a special type of file whose function is to link to another file, which may be of any type: a regular file, a directory, another symlink, etc. Reading from or writing to a symlink will access the file it represents. This makes the symlink appear to have no content of its own, but in reality it contains the text of the path to the file to which it links.

A symlink does not depend on the target file and continues to exist even if the target is moved or deleted. Moving or removing the target does not affect the symbolic link file; it will still have the same path although the path will now be invalid.

In the default ls colors, the filename of a symlink is shown in turquoise letters (the name of a broken symlink, one whose target path is no longer valid, is shown in red letters). A symlink can also be identified in the output of ls -l by the arrow after its filename pointing to the path of the file it links to.

lrwxrwxrwx 1 root root  22 Oct 23 12:43 telegram -> /opt/telegram/Telegram

The first letter l of the metadata string lrwxrwxrwx also identifies the file as a symlink. The letters rwxrwxrwx are the "dummy permissions" of the symlink. All symlinks have the same apparent permissions, but their real permissions are those of the file they link to. A user who does not have permission to read a file is not able to read the file by reading a symlink to it (thankfully).

The command to create a symlink is:

ln -s source destination

In this command, source is the filename or path that you want the symlink to point to, and destination is the name of the symbolic link created.

For example, if your current directory contains a file named test.sh, you can create a symlink to it using the command:

ln -s test.sh testlink

A new file named testlink will be created in the current directory and it will link to test.sh.

You can also use absolute paths. For example, using the absolute path to test.sh and creating testlink in the current directory:

ln -s /path/to/test.sh testlink

Using relative paths, which are relative to the directory that contains the symlink, may make the symlink more fragile. If a symbolic link holding a relative path is moved into another directory, the symlink will become invalid, unless its target was moved along with it. If you move a symbolic link that you created with an absolute path, the link will still be valid, as long as the target file has not also moved.

Symbolic links can also be created in graphical file browsers. For example, in some versions of Ubuntu, a contextual menu in a folder window or on the desktop may offer an option like Create Shortcut, which makes a symlink.

Related tags:

644 questions
656
votes
8 answers

How to create a soft or symbolic link?

I am installing p4v in /opt, but /usr/bin is on my path. Is it possible to create a soft or symbolic link for p4v from /opt to /usr/bin, so I can just type "p4v" since /usr/bin is in my path?
coffee
  • 6,783
585
votes
9 answers

What is the difference between a hard link and a symbolic link?

As the title says, I would like to know the difference between a hard link and a soft link created by the command ln. The command man ln does provide information, but does not sufficiently answer my question. Also, it would be nice if someone could…
ste_kwr
  • 11,540
291
votes
10 answers

How to list all symbolic links in a directory

I have a symbolic link in my /var/www/ directory that links to WordPress. When I run the command ls -la from the /var/www/ directory the link to WordPress doesn't show up. Is there a way to list all of the symbolic links that are in a directory?
Isaac
  • 3,105
  • 3
  • 15
  • 13
243
votes
6 answers

How to remove symbolic link

I was trying to create this symbolic link: sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin but I accidentally typed: sudo ln -s /usr/share/php,yad,in /var/www/phpmyadmin So now I want to correct it but it says symbolic link already exist.
James
  • 2,439
150
votes
1 answer

How to create a symbolic link in a linux directory?

I want to create a symlink that should point to another directory. Like inside directory /var/www/vhosts/ecash-staging.com/ should be a symlink named as ecash_root that should pointing to --> /var/www/vhosts/ecash_cfe. How is this possible ? I…
Waqas Rana
  • 1,611
127
votes
2 answers

Creating a symlink from one folder to another with different names?

I have two folders, one of which is my webserver root. I want to link it to my project folder so that I can keep things up-to-date with Git. If I try to do this: ln -s /home/user/project /var/www/html The system creates a folder called project…
user991710
  • 1,383
120
votes
5 answers

What is a "failed to create a symbolic link: file exists" error?

I'm trying to create a symlink in my home directory to a directories and files on my data partition. I've tried: ~/Documents$ ln -sv ~/Documents/saga /media/mariajulia/485f3e29-355c-4be3-b80a-1f5abd5604b6/mariajulia/Downloads/saga..doc to create a…
maria
  • 2,037
79
votes
3 answers

Help with creating a symbolic link

I'm confused with how symbolic links work. I hope someone can guide me in the right direction. I want to put a demo online from our software, which normally only runs locally on a Mac Mini. So I put all the files in the var/www from my Ubuntu 12.04…
user1737794
  • 891
  • 1
  • 7
  • 3
74
votes
5 answers

What is the difference between ln -s and mount --bind?

I am trying to understand difference between using ln -s and mount --bind. In basic scenario I can use both to access one directory from somewhere else. In what scenarios those two will behave differently ?
Łukasz
  • 962
56
votes
4 answers

How to find and list all the symbolic links created for a particular file?

I had created many symbolic links on various paths for a particular file or a directory. I want the whole list of created symbolic links paths (location). Example: I created symbolic links for ~/Pictures directory on many directories. How do I list…
Avinash Raj
  • 80,446
32
votes
6 answers

Symbolic Link: No such file or directory

I created a symbolic Link from a File at "/opt/bladir/bla" to "bla". So "bla" is now in "/usr/bin/bla". But if I want to call "bla" at terminal, there comes the no such file or directory error. I looked up at "/usr/bin/bla" and the file is linking…
Sehe
  • 323
30
votes
3 answers

Can symlinks be used in /etc/cron.d/?

I'm trying to implement a configuration mechanism that allows a cron configuration to deploy through SVN. I immediately thought that what I should do is create symlinks from /etc/cron.d/ to my project's cron file (which in turn is controlled by a…
26
votes
4 answers

how can I symlink my home folder from another drive?

More specifically, I want to have the user folder for my home account another disk that has more space, but keep my other smaller accounts on my ssd. I was able to copy my user folder to another disk, but now I need to link it to the home folder on…
sbergeron
  • 2,670
26
votes
1 answer

Is it possible to change the permissions for the symbolic link?

I am trying to change the permissions for the symbolic link. As how you can see in the image, the soft link has 777 permissions, but i would like to change that. I tried to change that by: chmod 755 someLink - but this changes linked directory…
ph7
  • 365
25
votes
6 answers

How to know if a folder is a symbolic link?

I am looking for a way, if it exists, to know if a the path to a folder is a symbolic link or the original path to the folder. Is there such a thing ?
Joseph Budin
  • 457
  • 1
  • 7
  • 14
1
2 3
42 43