> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Delete Soft Links in Linux
- URL: https://linuxhandbook.com/delete-links/
- Published: 2022-10-17T07:34:25.000Z
- Updated: 2022-11-12T14:19:57.000Z
- Description: Learn a thing or two about deleting soft links and hard links in the Linux command line.
- Author: Abhishek Prakash
- Tags: Tips

The symbolic link, also known as [soft link](https://linuxhandbook.com/symbolic-link-linux/) or symlink, in Linux is a special type of file that works as a shortcut to another file.

You can [create a soft link using the ln command](https://linuxhandbook.com/ln-command/). But what about deleting them?

**There is no special command for removing symbolic links in Linux**. You can use the [rm command which is also used for deleting files and directories.](https://linuxhandbook.com/remove-files-directories/)

```
rm symbolic_link_name
```

You may also the unlink command here. Don't go by its name. It's not only for deleting links; it can also delete files.

```
unlink symbolic_link_name
```

Let's see it in detail.

## Delete symbolic links using rm command

All you have to do is to give the name of the path of the link to the command:

```
rm name_or_path_of_link
```

Let's see it with an example. Can you identify the soft link in the long list output of ls command?

```
abhishek@LHB:~/test$ ls -l
total 4708
-rw-rw-r-- 1 abhishek abhishek 4794657 Sep 27 20:36 export.json
-rw-rw-r-- 1 abhishek abhishek     311 Sep 22 12:19 line.txt
lrwxrwxrwx 1 abhishek abhishek      26 Oct 17 11:24 mylink -> ./Documents/sample-mark.md
-rw-rw-r-- 1 abhishek abhishek     106 Sep 27 20:39 redirects.json
-rw-r--r-- 1 abhishek abhishek   12817 Sep 22 12:28 sample.txt
```

The link is called mylink. You can identify it in the long listing as it starts with the character `l` (for link) and the name shows the file it points to.

Let me delete the link and verify it:

```
abhishek@LHB:~/test$ rm mylink 
abhishek@LHB:~/test$ ls -l
total 4708
-rw-rw-r-- 1 abhishek abhishek 4794657 Sep 27 20:36 export.json
-rw-rw-r-- 1 abhishek abhishek     311 Sep 22 12:19 line.txt
-rw-rw-r-- 1 abhishek abhishek     106 Sep 27 20:39 redirects.json

```

💡

Deleting a soft link does not delete the original file it links to.

You can verify that the original file still exists.

![Deleting soft links in Linux with the rm command](https://linuxhandbook.com/content/images/2022/10/deleting-soft-links-with-rm-command-in-linux.png)

### Deleting multiple links

You can remove multiple symlinks at once with the rm command:

```
rm symlink1 symlink2 symlink3
```

[GridPaneGridPane helps WordPress agencies and developers build their own self managed WordPress hosting business.![](https://gridpane.com/wp-content/uploads/2019/03/Gridpane-Favicon.png)GridPane![](https://gridpane.com/wp-content/uploads/2021/02/GridPane-Self-Managed-WordPress-Hosting.jpg)](https://gridpane.com/?via=lhb&ref=linuxhandbook.com)

## Remove soft links using unlink command

Another way to delete soft links is by [using the unlink command](https://linuxhandbook.com/unlink-command/). It may sound like this command is only for removing links, it can delete files as well.

To remove a link with unlink, use it like this.

```
unlink name_or_path_of_link
```

I'll use the same example I used earlier.

![Removing soft link using unlink command](https://linuxhandbook.com/content/images/2022/10/deleting-soft-links-with-unlink-command-in-linux.png)

The unlink command is pretty limited. You can not delete multiple links at once with it.

## Delete soft link to a directory

You can create soft links to both files and directories. While you have to remove a directory with -r option, the link to a directory doesn't need that.

Use it the same way you used to delete link to a file:

```
rm name_or_path_to_link_to_dir
```

Don't use trailing slashes with the link else it will complain.

```
abhishek@LHB:~/test$ rm link_to_dir/
rm: cannot remove 'link_to_dir/': Is a directory
```

Here's an example of deleting a soft link to directory.

![Delete link to a directory in Linux](https://linuxhandbook.com/content/images/2022/10/delete-link-to-directory-in-linux.png)

⚠️

Never force remove a link to a directory with `rm -f` because it will delete the contents of the directory.

![](https://linuxhandbook.com/content/images/2022/10/force-deleting-directory-link.png)

Force deleting the link to the directory deletes the contents of the actual directory

## Deleting hard links

Unlike soft links, a [hard link](https://linuxhandbook.com/hard-link/) is almost indistinguishable from the original file. You can only notice it with the [inode](https://linuxhandbook.com/inode-linux/) number.

Can you identify the hard link and the file in the output? Pay attention to the inode numbers.

```
abhishek@LHB:~/test$ ls -li
total 4716
 544057 -rw-rw-r-- 1 abhishek abhishek 4794657 Sep 27 20:36 export.json
 544884 -rw-rw-r-- 2 abhishek abhishek     311 Sep 22 12:19 hard_link
 544884 -rw-rw-r-- 2 abhishek abhishek     311 Sep 22 12:19 line.txt
1181365 drwxrwxr-x 2 abhishek abhishek    4096 Oct 17 12:33 my_dir
 546419 -rw-rw-r-- 1 abhishek abhishek     106 Sep 27 20:39 redirects.json

```

And deleting a hard link is the same as deleting a file.

```
rm path_or_name_of_hard_link
```

## What about deleting the linked file?

I can't think of a scenario where you would want to delete the original file while removing the soft link automatically. 

Well, you can follow a symbolic link to get to the original file and use it to remove the file.

```
rm "$(readlink '/path/to/link')" /path/to/link 
```

💡

If you delete a file, keeping the soft link intact, the link becomes a broken or dangling link.

## Conclusion

While the unlink command exists, I recommend using the rm command for deleting symbolic links. You are already familiar with it and use this command for removing files. Use it for links as well. It's one [less command](https://linuxhandbook.com/less-command/) to remember.