unlink Command in Linux: Remove a Single File

unlink is a command-line utility that removes a single file by deleting its directory entry. Unlike the more powerful rm
command, unlink accepts only one filename at a time and has no functional options.
This guide explains how to use the unlink command with practical examples.
unlink Command Syntax
The syntax of the unlink command is as follows:
unlink filenameWhere filename is the name of the file you want to remove. On success, the command does not produce any output and returns zero.
unlink accepts only two informational options: --help, which displays usage information, and --version, which shows the version. There are no flags for forcing deletion, recursion, or verbose output — all of which are available in rm.
Removing a File
To remove a file, pass its name or path as the argument:
unlink file.txtTo remove a file in another directory, provide the full or relative path:
unlink /tmp/file.txtBe careful when removing files with unlink, because once a file is deleted recovery is often difficult and unreliable without backups.
Before deleting, you can quickly confirm the target exists with ls file.txt.
To remove write-protected files or files in directories you do not own, you need write permission on the parent directory. Otherwise you will get a “Permission denied” error. To remove more than one file, use rm
instead.
Removing a Symbolic Link
When removing symbolic links
with unlink, only the link itself is removed. The file the symlink points to is not affected.
unlink symlink_nameFor more ways to remove symbolic links, see How to Remove Symbolic Links in Linux .
Quick Reference
| Command | Description |
|---|---|
unlink file.txt | Remove a single file |
unlink /path/to/file.txt | Remove a file by full path |
unlink symlink_name | Remove a symbolic link (not its target) |
Troubleshooting
Permission denied
You do not have write permission on the directory containing the file. Either use sudo or change the directory permissions. Example error: unlink: cannot unlink '/opt/file.txt': Permission denied.
Is a directoryunlink cannot remove directories on GNU/Linux systems. Use rmdir
for empty directories or rm -r for non-empty ones. Example error: unlink: cannot unlink 'dir1': Is a directory.
Extra operandunlink accepts only one filename. Passing multiple filenames produces: unlink: extra operand 'file2.txt'. Use rm
to delete multiple files in one command.
FAQ
What is the difference between unlink and rm?unlink is a thin wrapper around the unlink() system call. It removes exactly one file and has no options. rm is more flexible — it supports multiple files, wildcards, recursive directory deletion (-r), and force mode (-f). Use unlink when you want a simple, explicit single-file deletion; use rm for everything else.
Can unlink delete multiple files at once?
No. unlink accepts only a single filename argument. Passing more than one filename produces an “extra operand” error. Use rm file1.txt file2.txt to delete multiple files in one command.
What happens when I unlink a file that is still open by a process?
The directory entry is removed immediately, so the filename disappears from the filesystem. However, the file’s data remains on disk until all processes that have it open close their file descriptors. The space is not freed until the last open handle is closed.
Can unlink delete a directory?
No. On GNU/Linux, unlink always fails with “Is a directory” when given a directory path. Use rmdir
for empty directories or rm -r for non-empty ones.
Conclusion
The unlink command is a simple tool for removing a single file from the command line. For more advanced file removal — multiple files, directories, or wildcards — use rm
. For a broader overview of file and directory removal on Linux, see How to Remove Files and Directories Using Linux Command Line
.
If you have any questions, feel free to leave a comment below.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page