Symlinks are a way of creating shortcuts to files or folders on your computer. They are useful when you want to access a file or folder from a different location without moving or copying it. Symlinks can be created using the ln command on Linux.
There are two types of symlinks: soft and hard. Soft symlinks point to a path in the file system, while hard symlinks point to the underlying inode of the file or folder. If you delete or move the target of a soft symlink, the symlink will be broken. However, if you delete or move the target of a hard symlink, the symlink will still work.
Creating a Soft Symlink
Soft symlinks are a type of file system object that point to another file or directory. They are also known as symbolic links or symlinks. Soft symlinks can be created with the ln -s command in Linux or Unix systems. Unlike hard links, soft symlinks do not share the same inode number as the target file or directory. This means that if the target is moved, deleted, or renamed, the soft symlink will become invalid and point to a non-existent location.
For this example, we wish to create a soft symlink to the file “traffic_reports” from the /afs/ directory and place the new link file in the root directory as “t_reports”.
The command to be used in this example is:
ln -s /afs/traffic_reports.txt /t_reports
To determine whether the command worked and that the new file was created, use the ls -la command to view the new soft symlink.
Creating a Hard Symlink
Hard symlinks are a type of file system link that point to the same data as the original file. Unlike soft symlinks, hard symlinks cannot cross file systems or point to directories. Hard symlinks are useful when you want to have multiple names for the same file without duplicating its contents.
For this example, we wish to create a hard symlink to the file “traffic_reports” from the /afs/ directory and place the new link file in the root directory as “t_reports1”.
The command to be used in this example is:
ln /afs/traffic_reports.txt /t_reports1
To determine whether the command worked and that the new file was created, use the ls -la command to view the new hard symlink.