How To Remove Symbolic Link In Linux With Example
Symbolic links or soft links works like pointers to another file. Note that there is only one copy of the actual file on the hard disk and in this way you can save valuable hard disk space by simply creating a link to it. Deleting a symbolic link is the same as removing a real file or directory.
Symbolic Links
1. Links have different inode numbers.
2. ls -l command shows all links with second column value 1 and the link points to original file.
3. Link contains the path for original file and not the contents.
4. Removing soft link doesn’t affect anything but removing original file, the link becomes “dangling” link which points to nonexistent file.
Symbolic links can be removed with two commands: rm and unlink. You can use any one of the following command to remove symbolic links.
1. rm – removes each given FILE including symbolic links
2. Unlink – deletes a single specified file name including symbolic links.
Delete Symbolic Link File
Below two commands are used to delete link.
# rm linkname
or
# unlink linkname
Example
Create soft link
# ln -s /etc/resolv.conf dns
List how soft link looks
# ls -l dns
Outputs:
lrwxrwxrwx 1 bob bob 16 2009-08-16 04:28 dns -> /etc/resolv.conf
Now delete above created symbolic link dns.
# rm dns
OR
# unlink dns
Delete Symbolic Link Directory
Below two commands are used to delete link directory
# rm linkDirName
or
# unlink linkDirName
Example
Create soft link
# ln -s /etc link1
List how soft link looks
# ls -l link1
Sample Output:
lrwxrwxrwx 1 bob bob 4 2009-08-16 04:31 link1 -> /etc
Now delete test symbolic link directory.
# rm test
or
# unlink test
When using the rm or unlink command to remove a symbolic link to a directory, make sure you don’t end the target with a ‘/’ character because it will create an error.
Example
$ mkdir dirfoo
$ ln -s dirfoo lnfoo
$ rm lnfoo/
rm cannot remove directory ‘lnfoo/’ : Is a directory
$ unlink lnfoo/
unlink: cannot unlink ‘lnfoo/’: Not a directory
$ unlink lnfoo
$
Category: LINUX HOWTO




