• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Delete (Remove) Symbolic Links in Linux

Written by Admin, Updated On June 11, 2020
find, rm, terminal
How to Delete (Remove) Symbolic Links in Linux

A symbolic link is also known as symlink or soft link, is a special type of file that serves as a reference to another file or directory. A symlink can point to a file or a directory on the same or a different filesystem or partition. This guide explains how to remove symbolic links in Linux systems.

Before going ahead for removing symbolic link, make sure use have writing permission on parent directory of the symlink. Otherwise, you will get “Operation not permitted” error.

To check symlink and to find the destination directory or file, use ls -l command.

ls -l /home/file.php
lrwxrwxrwx 1 tecnstuff tnsgrp 4 May 2 14:03 /home/file.php -> file_link.php

In above output the first character l shows that the file is symlink and the arrow -> symbol indicates where the symlink points to.

Remove Symbolic Links with rm#

To remove a symbolic link, use the rm command followed by the symbolic link name. Using rm command you can remove given file or directories.

rm SYMLINK_NAME

For example, to delete the /home/file.php symlink, you would run following command:

rm /home/file.php

It will not show output and exits with zero.

If you would like to delete more than one symbolic link, you can pass multiple symlink names as arguments with space separated.

rm SYMLINK_NAME_1, SYMLINK_NAME_2

If you would like to prompt confirmation message before deleting the symlink, you should pass -i option along with rm command:

rm -i SYMLINK_NAME

Type y and press Enter key for confirmation.

You will get following output:

rm: remove symbolic link 'SYMLINK_NAME'?

Ensure that you never use -r option along with rm command while removing symlink. Otherwise it will remove all the contents of the destination directory.

Remove Symbolic Links with unlink#

Unlink command removes the given symlink. It is possible to delete only a single file using unlink.

To remove a symlink using unlink, run the following command followed by the symlink name.

unlink SYMLINK_NAME

For instance, to remove the /home/file.php symlink, you would run following unlink command:

unlink /home/file.php

When removing a symbolic link that points to a directory do not append a trailing slash to the symlink name.

Conclusion#

This tutorial shown you how to remove symbolic links or symlink using rm or unlink command.

If you have any question or feedback, please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article Unlink Command in Linux (Remove File)
Next Article   How to Check if a File or Directory Exists in Bash

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook