← All commands
THE COMMAND REFERENCE

unlink

Remove one file with the plain one-argument form.

Last updated

macOS / Apple

Implementation-level reference; examples are not certified for every installed version.

Overview

unlink removes a single file or link. It does what rm FILE does for one file, but it takes no options and never asks. It mirrors the system function of the same name, which removes one name of a file.

Background

Today the name covers GNU unlink, the unlink that macOS ships, and the unlink applet in BusyBox. The macOS manual has no separate page for unlink, so no date is given. All three take exactly one argument.

Examples

Remove a file and check that it is gone:

unlink app.log && { ls app.log 2> /dev/null || echo gone; }

Remove one name of a hard link; the other name still works:

ln notes.txt hard.txt && unlink hard.txt && head -n 1 notes.txt

Remove a symbolic link without touching its target:

ln -s notes.txt link && unlink link && head -n 1 notes.txt

Common mistakes

unlink accepts exactly one name; it has no -r or -f, and it does not remove directories on most systems, so use rmdir or rm -r for those. It does not ask for confirmation, and the file is gone at once, so check the name before you press Enter. When a file has several hard links, unlink removes only the name you gave.

Portability

Only the one-argument form exists, and it is the same on all three implementations. rm is more common and safer in scripts because of its options. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).

About macOS unlink

This is the unlink in the system folders of macOS. It follows the BSD implementation.

Apple notes

macOS unlink takes exactly one argument.

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.