dirname(1)

dirname1

Return directory portion of pathname

Usage

dirname pathname

Overview

dirname deletes the filename portion, beginning with the last slash (‘/’) character to the end of pathname, and writes the result to the standard output.

Exit status

The dirname utility exits 0 on success, and >0 if an error occurs.

Examples

The following line sets the shell variable FOO to /usr/bin:

FOO=`dirname /usr/bin/tail`

Releases

61 releases since OpenBSD 2.1; the text changed 11 times.

  1. 2.1–2.2
  2. 2.3
  3. 2.4–2.5
  4. 2.6
  5. 2.7–2.9
  6. 3.0
  7. 3.1–3.3
  8. 3.4–4.1
  9. 4.2–4.4
  10. 4.5–4.8
  11. 4.9–5.4
  12. 5.5–8.0

Standards

The dirname utility is compliant with the IEEE Std 1003.1-2008 (“POSIX.1”) specification.

History

The dirname utility first appeared as an expr(1) script in AT&T System III UNIX. It was reimplemented in C for 4.3BSD-Reno and reimplemented again using dirname(3) for OpenBSD 2.2.

Authors

The original BSD version was written by Keith Bostic. The current OpenBSD version was written by Todd Miller ⟨[email protected]⟩.

From man 8.0-current-20261101 in OpenBSD 8.0-current (2026-11-01). Parsed by carta from the page's mdoc source.