Skip to Content
gnux

unlinkx

Call the unlink function to remove the specified file.

Mirrors GNU unlink. Run it as unlinkx, or as gnux unlinkx.

Synopsis

unlinkx FILE

GNU reference

Description

unlinkx removes the single name FILE with the unlink(2) system call. It takes exactly one operand and no options: it never recurses, never prompts, never ignores a missing file, and refuses a directory, even an empty one, with 'Is a directory' (use rmdirx for that). A symbolic link is removed, not its target. Removing the last name of a file frees its data once no process has it open.

Permissions

Needs write and search permission on the directory containing FILE; permission on FILE itself does not matter. In a directory with the sticky bit set (such as /tmp), only the file's owner, the directory's owner or root may remove it. On Windows, a read-only file or one open in another process cannot be removed.

Use cases

  • Removing exactly one file in a script, failing loudly if anything is unexpected.
  • Removing a symbolic link without any risk of touching what it points to.
  • Releasing a lock file created with linkx.
  • Removing a file whose name could be mistaken for an option, with --.
  • Removing one of several hard links while keeping the others.

Flags

      --help      display this help and exit
      --version   output version information and exit

Examples

Remove one file

unlinkx old.log
unlinkx current

A directory is refused (use rmdirx)

unlinkx build || rmdirx build

Release a lock file

unlinkx app.lock

Remove a file whose name starts with a dash

unlinkx -- -oops
linkx data data.bak && unlinkx data

Fail when the file is already gone (rmx -f would not)

unlinkx tmp.txt || echox 'nothing to remove'

Remove a file with spaces in its name

unlinkx 'my file.txt'

Remove a temporary file at the end of a script

tmp=$(mktempx) && echox data > "$tmp" && unlinkx "$tmp"

Remove a file in the portable gnux shell

gnux shell -c 'unlinkx out.txt'

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

unlinkx --help                # options, first examples, exit status
gnux help unlinkx             # this page: the full manual
gnux help unlinkx --OPTION    # one option in depth, with its examples

See also

On this page