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:

623 questions
626
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,483
  • 4
  • 16
  • 6
562
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,020
  • 8
  • 28
  • 37
271
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
  • 2,905
  • 3
  • 13
  • 13
211
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,119
  • 2
  • 12
  • 3
133
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,441
  • 2
  • 9
  • 7
121
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,323
  • 2
  • 9
  • 6
111
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,947
  • 4
  • 24
  • 33
77
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
  • 871
  • 1
  • 7
  • 3
65
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
  • 872
  • 1
  • 6
  • 8
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
  • 77,204
  • 56
  • 214
  • 254
28
votes
3 answers

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

I'm trying to implement a configuration mechanism that allows in a certain project to deploy through svn a cron configuration. I immediately thougt that what I should do is cerate symlinks from /etc/cron.d/ to my project's cron file (which in turn…
Luís Faceira
  • 281
  • 1
  • 3
  • 3
27
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
  • 273
  • 1
  • 3
  • 5
25
votes
3 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
  • 7
  • 31
  • 42
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
23
votes
2 answers

force cp to copy on dangling symlinks

Is there any way to force cp (Bash 4.2.5, Ubuntu 12.04) to copy onto a dangling symlink? cp a-file path/to/danling/symlink/a-file cp: not writing through dangling symlink `path/to/danling/symlink/a-file` cp -f seems to be impotent in this case and…
Marcus Junius Brutus
  • 787
  • 4
  • 11
  • 29
1
2 3
41 42