What is symbolic link, soft link or symlink

What is a symbolic link, soft link, or symlink

A symbolic link (also known as a soft link or symlink) consists of a special type of file that references another file or directory. Unix/Linux-like operating systems often use symbolic links. Here we will see how to use the ln command to create symbolic/soft links.

There are two types of links

  • symbolic links (also known as “soft links” or “symlinks”): Refer to a symbolic path indicating the abstract location of another file.
  • hard links: Refer to the specific location of physical data.

Here is How to create a soft link / symbolic link under Unix and Linux?

Soft links are created with the ln command. For example, the following would create a soft link named link1 to a file named file1, both in the current directory

$ ln -s file1 link1

To verify new soft link run:

$ ls -l file1 link1

Here is How to use the ln command

So the syntax is as follows to create a symbolic link in Unix or Linux, at the shell prompt:
$ ln -s {source-filename} {symbolic-filename}

Here is Creating Symlink to a directory

The syntax remains same:
$ ln -s {source-dir-name} {symbolic-dir-name}
For example, create a symbolic link from the /home/lighttpd/http/users/satya/php/app/ directory to the /app/ directory you would run:
$ ln -s /home/lighttpd/http/users/satya/php/app/ /app/

Here is How to overwrite symlinks/Soft link

Pass the -f to the ln command to overwrite links:
ln -f -s /path/to/my-cool-file.txt link.txt

Here is How to delete or remove symlinks/soft links

Use the rm command to delete a file including symlinks:
rm my-link-name
unlink /app/
rm /home/satya/index.php

Here is all the options of ln command

ln command optionDescription
--backupmake a backup of each existing destination file
-blike --backup but does not accept an argument
-dallow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser)
-fremove existing destination files
-iprompt whether to remove destinations
-Ldereference TARGETs that are symbolic links
-ntreat LINK_NAME as a normal file if it is a symbolic link to a directory
-Pmake hard links directly to symbolic links
-rcreate symbolic links relative to link location
-smake symbolic links instead of hard links
-Soverride the usual backup suffix
-tspecify the DIRECTORY in which to create the links
-Ttreat LINK_NAME as a normal file always
-vprint name of each linked file
--helpdisplay this help and exit
--versionoutput version information and exit