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 option Description
--backup make a backup of each existing destination file
-b like --backup but does not accept an argument
-d allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser)
-f remove existing destination files
-i prompt whether to remove destinations
-L dereference TARGETs that are symbolic links
-n treat LINK_NAME as a normal file if it is a symbolic link to a directory
-P make hard links directly to symbolic links
-r create symbolic links relative to link location
-s make symbolic links instead of hard links
-S override the usual backup suffix
-t specify the DIRECTORY in which to create the links
-T treat LINK_NAME as a normal file always
-v print name of each linked file
--help display this help and exit
--version output version information and exit