Files
unlink
Remove a file using the unlink system call.
fileremovedeleteunlinkdirectory entry
Additional Notes
unlink removes a file by calling the unlink() system call directly. It deletes the directory entry for the specified file and decrements its link count. If the link count reaches zero and no process has the file open, the file is removed from disk.
Unlike rm, unlink accepts only a single file argument and provides no options for recursive deletion, prompting, or interactive behavior. It is a minimal command that closely reflects the underlying system call. If the file does not exist or if the user lacks write permission on the parent directory, unlink fails with an error.
Syntax
unlink filename
Parameters
filename: Path to the file to remove.
Examples
unlink file.txt
Remove file.txt.
unlink /tmp/socket.lock
Remove a lock file or socket.
Practical Notes
unlinkcannot remove directories. Usermdirorrm -rfor that.unlinkdoes not prompt or confirm deletions.- The command is defined by POSIX and available on all Unix-like systems.
- For most purposes,
rmis preferred because it offers more flexibility and safety options. Useunlinkwhen you need strict POSIX compliance or when a script must use the direct system call semantics.