
unlink Command in Linux
The unlink command in Linux is a basic tool used to delete a single file or symbolic link. It is different from the rm command, which can handle many files and directories at once. Unlink is designed specifically for deleting one file or link at a time. It removes the file from its directory list and disconnects its inode, which means the file or link is deleted.
The unlink command is useful when you want to remove a file precisely and don't need extra options or prompts. It's a straightforward option when you want to make sure only one specific file or link is gone without any fuss.
Table of Contents
Here is a comprehensive guide to the options available with the unlink command −
- Installing of unlink Command
- Syntax of unlink Command
- unlink Command Options
- Examples of unlink Command in Linux
Installing of unlink Command
The unlink command is typically pre-installed on most Linux distributions. However, if it is not available, you can install it using your system's package manager −
Debian-Based Systems (Ubuntu, Linux Mint, etc.)
sudo apt install coreutils
Red Hat-Based Systems (RHEL, CentOS, Fedora)
sudo yum install coreutils
Arch Linux and Manjaro
sudo pacman -S coreutils
Syntax of unlink Command
The unlink command follows a simple syntax −
unlink filename
Where, filename is the name of the file or symbolic link you wish to remove.
unlink Command Option
The unlink command does not support multiple options like rm. It is intentionally kept simple to perform single file removals safely. The following are key characteristics −
- No confirmation prompts − Once executed, the file is deleted without warnings.
- No recursive deletion − It does not work on directories.
- Works only on single files or symbolic links − Unlike rm, it cannot remove multiple files in one command.
While unlink does not have traditional options, it behaves differently when applied to symbolic links, as explained in the next section.
Examples of unlink Command in Linux
Let's explore a few practical examples of unlink command on Linux system −
- Removing a Single File
- Removing a Symbolic Link Without Deleting the Original File
Removing a Single File
Imagine you have a log file, server.log, that you no longer need. To delete it −
unlink server.log
With this command, the file server.log is removed instantly. Unlike rm, this command does not prompt for confirmation. Recovery is not possible, so be sure you want to delete the file.

Removing a Symbolic Link without Deleting the Original File
Let's say shortcut_link is a symbolic link pointing to important_data.txt. If you only want to remove the link without affecting important_data.txt, use −
unlink shortcut_link
After executing this command, the link shortcut_link is deleted, but important_data.txt remains untouched. If you try to access shortcut_link afterward, it will not exist.

Conclusion
The unlink command in Linux is specifically designed to delete one file or symbolic link at a time. This sets it apart from the rm command, which can handle multiple files and entire directories. When you execute the unlink command, it removes the file from its folder and disconnects it from its inode, making file recovery impossible.
Since unlink does not ask for confirmation before deleting, it's important to use it carefully. This command is particularly useful for dealing with symbolic links without disturbing the original files. By understanding how unlink works, you can avoid accidental deletions and maintain your file system efficiently.