Skip to content

unlink Command Cheat Sheet

unlink calls the unlink system call to remove a specified file.


Synopsis

unlink FILE

Usage

Remove a File

unlink file.txt
unlink symlink_name

Feature unlink rm
Input Only 1 filename Multiple files, directories
Recursion No Yes (-r)
Safeguards None (No -i) Interactive (-i), Force (-f)
Directories Cannot remove Can remove (-r or -d)
System Call Direct unlink() Wraps unlink() with logic

Summary: unlink is simpler and more limited. It is mostly used when you want to be strictly sure you are not traversing directories or handling wildcards implicitly.


Notes

  • Error: If you try unlink directory/, it will fail (unlike rm -d).
  • Data: It removes the directory entry. The data blocks are freed only if no other hard links exist and the file is not open by any process.