How To Remove Soft Link In Linux
Symbolic links or Soft links work like pointers to some other file. Note that there is only ane copy of the actual file on the hard disk and in this way y'all tin can salvage valuable difficult deejay space past simply creating a link to it. Deleting a symbolic link is the aforementioned as removing a existent file or directory.
A symbolic link is a link that refers to the name of a file. Its nigh important reward is that information technology can be used to refer to a file that is anywhere, even on a figurer on the other side of the globe. The symbolic link will still work. However, the biggest disadvantage is that the symbolic link is naturally dependent on the original file. There are some properties of symbolic links
- Links have different inode numbers : every Linux file or directory (from a technical point of view, there's no existent difference between them) has an inode and this inode contains all of the file's metadata (that is, all the administrative data needed to read a file is stored in its inode)
-
ls -fiftycommand shows all links with second column value1and the link points to original file. - Link contains the path for original file and not the contents.
- Removing soft link doesn't bear upon annihilation only when the original file is removed, the link becomes a dangling link that points to nonexistent file.
rm and unlink commands to remove symbolic link
Symbolic links tin can be removed with two commands: rm and unlink. You tin utilize any ane of the post-obit commands to remove symbolic links.
- rm: is the terminal command to remove each given file including symbolic links. Because a symbolic link is considered as a file on Linux, you tin can delete it with the rm command.
# rm linkfile - unlink: deletes a unmarried specified file name including symbolic links.
# unlink linkfile To remove the symbolic link file, you should list it with ls -50 command as below
# ls -l pac lrwxrwxrwx 1 root root ix May xviii 01:57 pac -> /root/pac pac -> /root/pac shows the path of the original file which is /root/pac and the one value on the 2nd column indicates that the file is a symbolic link file.
Warning: The control rm and unlink delete files and then should be used carefully, make sure you accept a proper backup before proceeding. Delete symbolic link file - Instance
To see how we tin delete symbolic link file, we will commencement create a soft link a below
# ln -due south /root/script /home/papso To list how soft link looks:
# ls -fifty script lrwxrwxrwx 1 root root 12 May eighteen 02:32 script -> /root/script To delete symbolic link, you can employ its relative or accented path but to limit fault, I recommend you lot to use a relative path.
With accented path nosotros have
# rm /habitation/papso/script or you can do
# unlink /home/papso/script Nosotros can check as below
# ls -l /home/papso/script ls: cannot access script: No such file or directory With relative path, we start need to move to the symbolic link file directory
# cd /dwelling house/papso At present you tin use one of the commands above
# unlink script and check with
# ls -l script ls: cannot admission script: No such file or directory Be careful when you use unlink command because information technology tin can delete regular file. If yous write an existing regular filename instead of a symbolic link filename, the regular file volition be deleted. Encounter below
# ls -fifty file1 -rw-r--r-- 1 root root 0 May 18 02:51 file1 Yous can meet that file1is non a symbolic link. Now we will use unlink command and nosotros volition see the result.
# unlink file1 # ls -l file1 ls: cannot access file1: No such file or directory Y'all see thatfile1doesn't exist. It has been deleted
Delete symbolic link directory - Example
To delete a symbolic link directory, we will employ the aforementioned procedure as to a higher place. We volition create a soft link:
# ls -ld pac drwxr-xr-x 2 root root 4096 Apr half-dozen 22:54 pac pac is the folder which volition be used for the test.
# ln -s /root/pac /home/papso/examination Check
# ls -l /home/papso/test/pac lrwxrwxrwx 1 root root ix May 18 03:00 /domicile/papso/examination/pac -> /root/pac At present to delete the test symbolic link directory, we will use the relative path. Nosotros accept moved to /abode/papso/test folder
# rm pac or
# unlink pac We will bank check now with absolute path
# ls -50 /home/papso/examination/pac ls: cannot access /home/papso/test/pac: No such file or directory unlink command and rm command without -R pick doesn't delete regular directory. The 2 commands delete symbolic link from directory because it's considered as a file so, when using the rm or unlink command to remove a symbolic link from a directory, make sure you don't end the target with a / character because that volition create an mistake.
Come across beneath
$ mkdir dirfoo $ ln -s dirfoo lnfoo Permit's cheque
# ls -50 lnfoo lrwxrwxrwx ane root root 6 May 18 03:16 lnfoo -> dirfoo Now let'south effort to delete the symbolic link
# rm lnfoo/ rm cannot remove directory 'lnfoo/' : Is a directory Because the / at the end indicates a directory, the command doesn't work
# unlink lnfoo/ unlink: cannot unlink 'lnfoo/': Not a directory At present let's try without the / character at terminate of the filename
# unlink lnfoo Now permit's bank check it the file exists
# ls -l lnfoo ls: cannot admission lnfoo: No such file or directory You can see that the symbolic link has been deleted
Conclusion
Basically, a symbolic link makes it easier to find files you need. You tin create symbolic links for the files, directories and you can employ them to make life easier for users every bit well. Symbolic link is considered as a normal file because you lot can delete it with the basic rm command. Don't forget the biggest disadvantage which imply that the symbolic link is naturally dependent on the original file.
Read Also:
- Hard Link vs Soft Link in Linux with Examples
How To Remove Soft Link In Linux,
Source: https://linoxide.com/remove-symbolic-link/
Posted by: watershasked.blogspot.com

0 Response to "How To Remove Soft Link In Linux"
Post a Comment