TranslateProject/sources/tech/20190921 How to Remove (Delete) Symbolic Links in Linux.md
2019-09-23 01:03:25 +08:00

4.1 KiB
Raw Blame History

#: subject: (How to Remove (Delete) Symbolic Links in Linux) #: via: (https://www.2daygeek.com/remove-delete-symbolic-link-softlink-linux/) #: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)

How to Remove (Delete) Symbolic Links in Linux

You may have the opportunity to create or remove symbolic links on Linux.

If yes, do you know how to do it?

Have you already done that? Are you aware of that?

If yes then there is no problem. If not, dont worry, we are here to help you with this.

This can be done using the rm and unlink commands.

A symbolic link, also known as a symlink or soft link, is a special type of file that points to another file or directory in Linux.

Its similar to a shortcut in Windows.

It can point to a file or a directory on the same or a different filesystem or partition.

In general Symbolic links are used to link libraries. Also, used to link log files and folders on mounted NFS (Network File System) shares.

What is rm Command?

The rm command is used to remove files or directories. This is very dangerous and be cautious every time you use the rm command.

The unlink command is used to remove the specified file. It is already installed as it is part of the GNU Gorutils.

The rm command is one of the most frequently used commands in Linux. Furthermore, it allows us to remove the symbolic links as described below.

# rm symlinkfile

Always use the rm command with the “-i” switch to understand what is being done.

# rm -i symlinkfile1
rm: remove symbolic link symlinkfile1? y

It also allows us to remove multiple symbolic links at once.

# rm -i symlinkfile2 symlinkfile3

rm: remove symbolic link symlinkfile2? y
rm: remove symbolic link symlinkfile3? y

This is like removing a symbolic link file.

Use the below command to remove Symbolic Link directory.

# rm -i symlinkdir

rm: remove symbolic link symlinkdir? y

Use the below command to remove multiple Symbolic Link directory.

# rm -i symlinkdir1 symlinkdir2

rm: remove symbolic link symlinkdir1? y
rm: remove symbolic link symlinkdir2? y

If you add “/” trailing slash at the end, the symbolic link directory cannot be deleted. If you add, you get an error.

# rm -i symlinkdir/

rm: cannot remove symlinkdir/: Is a directory

You may need to add the “-r” switch to deal with the above problem. If you add this, it will delete the contents of the target directory, while it will not delete the symbolic link directory.

# rm -ri symlinkdir/

rm: descend into directory symlinkdir/? y
rm: remove regular file symlinkdir/file4.txt? y
rm: remove directory symlinkdir/? y
rm: cannot remove symlinkdir/: Not a directory

The unlink command deletes a given file. It accepts only a single file at a time.

To delete symbolic link file

# unlink symlinkfile

To delete symbolic link directory

# unlink symlinkdir2

If you append the “/” trailing slash at the end, you cannot remove the symbolic link directory using the unlink command.

# unlink symlinkdir3/

unlink: cannot unlink symlinkdir3/: Not a directory

via: https://www.2daygeek.com/remove-delete-symbolic-link-softlink-linux/

作者:Magesh Maruthamuthu 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出