basename(1)

basename1

Return filename portion of pathname

Usage

basename string [suffix]

Overview

basename deletes any prefix ending with the last slash (‘/’) character present in string, and a suffix, if given. The resulting filename is written to the standard output. A non-existent suffix is ignored.

Exit status

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

Examples

The following line sets the shell variable FOO to tail:

FOO=`basename /usr/bin/tail`

Releases

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

  1. 2.1–2.2
  2. 2.3
  3. 2.4–2.5
  4. 2.6
  5. 2.7–3.3
  6. 3.4–4.1
  7. 4.2–4.4
  8. 4.5–4.8
  9. 4.9–7.5
  10. 7.6–8.0

Standards

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

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