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:

629 questions
637
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,593
570
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,210
216
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,169
  • 2
  • 13
  • 3
140
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,511
116
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
  • 1,997
78
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
  • 881
  • 1
  • 7
  • 3
30
votes
4 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
  • 303
25
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,660
24
votes
4 answers

symlink to already existing directory

Is there a proper way to link /home/user/app/public to /home/user/public_html, considering the fact that the target already exists? If I do ln -s /home/user/app/public /home/user/public_html, I end up having /home/user/public_html/public. I guess it…
user2094178
  • 343
  • 1
  • 2
  • 5
20
votes
4 answers

Remove all symlinks in a folder

How do I remove all symlinks in a folder (dozens of them) at once? It's not practical to insert every single one of them by hand when using unlink or rm.
20
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
  • 407
  • 1
  • 5
  • 13
12
votes
0 answers

Symbolic links vs Hard links

I just read the manpage for symlinks, but I still dont get it ... so hardlinks are pointers to the file/dir. Then symlink is a pointer to a pointer? Whats the use of a symlink then? Why/when should I use one over the other?
JM at Work
  • 1,965
11
votes
3 answers

What's the difference between ln -s and mount --rbind?

What's the difference between: ln -s /mnt/extra/home / and mkdir /home mount --rbind /mnt/extra/home /home
user8292439
  • 3,808
9
votes
1 answer

Unable to create a symlink to a file

I am not able to create a simple symlink here. When I tried the command sudo ln –s /home/vivek/Downloads/drush/drush /home/vivek/Documents/ where drush is a file inside the folder named drush, I get the following error, ln: accessing `–s': No such…
Vivek
  • 3,749
7
votes
4 answers

How to find the original file of a soft link?

For example, I have a file a, and I do the followings. ln -s a b ln -s b c ln -s c d If I use readlink d, I will get c. So I have to run many times to get a. Is there an easy way to get a? Update: If I want to locate the original file of…
1
2 3 4 5 6