How to Create Softlink and Hardlink on Redhat 8

Create Softlink and Hardlink on Redhat 7/Redhat 8/Redhat 9/Centos 7/Centos 8

Hard links and soft links to make the multiple name points to same file.

Soft link: Soft link is also known as symbolic link or short pointer. By use of Soft link main file (regular file) link with multiple Soft link (non-regular files). With the help of soft link important files can be read from less privilege user id. In soft link main file (regular file) remain safe if soft link non-regular file delete but if main file (regular file) delete all other soft link non-regular files become unusable because it work as readable copy of main file. Soft link main file (regular file) and soft link non-regular files have different inode number, soft link non-regular files have also different permission as soft link main file (regular file) and the permission of soft link non-regular files is not change. Soft link allow link files between the directories and different file systems (mount points). The soft link in Linux have a similar concept as shortcut in windows base operating system. Soft link is slow as compare to hard link and soft link can link to both files and directories. When the original file is delete, the softlink is still pointing to the file but the target has gone. A Soft link pointing to a missing file is called "dangling soft link".

To create a soft link use command “ln -s”. A soft link is a special file type that point to an existing file or directory. Below is the example to create a soft link, in this example original file is “original-file.txt” and its soft link or symbolic link file is “newfile-symlink.txt”.

ln -s /owais/original-file.txt /khan/newfile-symlink.txt

To list the original file and soft link or symbolic link files, type the below mention command.

ls -l /owais/original-file.txt /khan/newfile-symlink.txt

To create a soft link of directory “/etc” to directory “/owais/config-files”, type the below mention command.

ln -s /etc /owais/config-files

To verify the link has successfully create, type the below mention command.

ls -l /owais

Hard Links: A hard link is a new directory entry with a reference to an existing file system. A hard link is the similar copy of original file. If the original file is delete, the content of the file is available if at least one hard link exist. When original file is modify the all other hard link file that relate to the original file automatically updated. When hard link is create of any file, after a new hard link is created there is no way to tell which file is original; in other words you can say that hard link is the another name of a file that already exist. Multiple hard link can created of the same file and all hard links and original file have same inode number. Hard link is create inside the same file system that why it is faster as compare to soft link.

To create a hard link from the original file, type the below mention command. In the below example command the original file is “owais.txt” and newly created hard link file is “newfile-hlink.txt”.

ln owais.txt /owais/newfile-hlink.txt

To list the original hard link file and newly created hard link file, type the below mention command.

ls -l owais.txt /owais/newfile-hlink.txt

Thanks For Read this Article

Comments