21. symbolic _links - muneeb-mbytes/linux_course GitHub Wiki

Symbolic Links

Link

The connection between the file and the actual data on the disk .

A symlink is a symbolic Linux/ UNIX link that points to another file or folder on your computer, or a connected file system. This is similar to a Windows shortcut.

There are two types of symbolic link forms :

Softlink

Soft links are similar to shortcuts, and can point to another file or directory in any file system.

Soft link will be removed if original file removed or delete.

Syntax: ln -s /<path to file/folder to be linked> <link_name>


Hardlink

Hard links are also shortcuts for files and folders, but a hard link cannot be created for a folder or file in a different file system. These can be created in the following way on Linux and Mac operating systems.

Deleting , renaming or removing file will not effect the hard link .

Hard links are useful as a kind of backup for files.

Syntax: ln /<path to file/folder to be linked> <link_name>

To check it write command "ls -ltr".


Unlink

We can also unlink the hardlink and softlink . This can be done by using the command "unlink" and is same for both softlink and hardlink .

Syntax : unlink <link_name>


Steps to create a symbolic path to get into another directory:

  • Get into the directory from where you need to create a symbolic link.
  • Enter the command ln -s links_path link_name.
  • A link will be created in the current directory.
  • In order to get to the created link use the command cd link_name.
  • Now you will be inside the directory for which you created a symbolic link

Symbolic_link

Gif. shows an example of how to create a symbolic link and get into a directory.

  • direct_path is a directory that is inside the symbolic_link directory.
  • new_path is a directory that is inside the direct_path directory.
  • Now in order to create a link directly from symbolic_link to new path_path make sure you are in the home directory from where the path need to be created.

In this example cd ../../ is used to comeback 2 directories behind so that link will be created from the symbolic_link directory(make sure you are in the proper directory for creating link).

Now we created link using command ln -s direct_path/new_path/ link_to_new_path.
Here, ln -s is a command used for creating symbolic links. direct_path/new_path/ is the path for which the link is to be created. link_to_new_page is a name given to the link created.

Now we are getting inside the new_path directory by entering the command cd link_to_new_path, which will now take us into the new_path directory without entering its actual path.

we can verify the actual path and symbolic path using PWD commands.
pwd -P will show the actual path for entering into the new_path directory. pwd -L will show the symbolic path for entering into the new_path directory.


To learn ps command: https://github.com/muneeb-mbytes/linux_course/wiki/22.-ps-command

⚠️ **GitHub.com Fallback** ⚠️