A symbolic link, also called a soft link or even sometimes a symlink, is essentially a file that contains a reference to some other file and allows you to access it without entering the full path of the original file. You can link to regular files or directories, and many operating system packages use this to their advantage. For instance, users of Wine on Linux or FreeBSD might have seen a directory called dosdevices that contains symbolic links to simulated MS-DOS drives to aid in running Windows programs.
Eventually, you might need to either remove symbolic links you create yourself or ones left over from a program. You might even receive an error message that reads “Too many levels of symbolic links,” which shows that a link is linked back to itself in a never-ending cycle.
Method 1: Removing Symbolic Link Files
While you shouldn’t go removing links without a good reason, one single command will do it for you with a minimum of playing around. Open a terminal window by holding down Ctrl, Alt and T at the same time. You could also search for it by clicking on the Dash if you’re using Unity or start it by clicking on the Applications menu and selecting it from System Tools if you use KDE, Xfce4, LXDE or another desktop environment.
At the prompt use cd to navigate to where the offending link is and then use rm -i linkName to remove the link, having replaced linkName with the actual name of the link. You’ll be given a prompt that reads “rm: remove symbolic link ‘linkName’?” to which you can type y and push enter. The offending link is thus removed. While you could remove a link merely by using rm by itself, it’s best to use the -i switch to force the prompt so you can make sure it really is a symbolic link you’re removing. If it reads something else, then you can always type n to cancel it.
For the sake of practice, we headed into the /tmp directory and used mkdir bob to create a directory then linked to it with ln -s bob jamie to actually make a symbolic link. You could always use ln -s name1 name2 to create a symbolic link to any file or directory anywhere in a file system. For instance, would create a symlink in the current directory called edit that points to the system wide nanorc file. You could then access it like it was any other file and even use more edit to have a look at it.
Once you’re done, you could then use rm -i edit to remove the symbolic link without ever touching the actual file. This one command is enough to pull any link that your user account has the access to pull without needing to play around any further. If you’re ever caught trying to fix the dreaded “Too many levels of symbolic links” error with a symlink that requires higher privileges to work around, then try sudo rm -i edit to delete the file. The system should prompt you for your password and then ask to delete your user account.
Method 2: Unlinking symlinks
You can also remove symbolic link entries in any directory by typing unlink linkName, where linkName is the name of the entry. So you could type unlink edit to remove the file above. Since it doesn’t provide the sanity checking or the nice prompt that the rm -i command does, it doesn’t come nearly as recommended, but it does work and since it doesn’t take any options it’s debatable that it’s easier to use, though neither technique should take much playing around.
You’ll also always find rm on every Unix system, whether it’s based on Linux, BSD, Solaris, macOS or even something else hence it’s often the preferred way to go.
PRO TIP: If the issue is with your computer or a laptop/notebook you should try using the Reimage Plus Software which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Reimage Plus by Clicking Here