maux
Star on GitHub Buy me a coffee

Manual / dirname

dirname(1)

DIRNAME(1) General Commands Manual DIRNAME(1)

dirname - return all but the last component of a pathname

dirname string

Dirname deletes the last component of string, beginning with the last slash (/) character, after first stripping trailing slashes, and writes the result to standard output.

If string consists entirely of slashes, a single / is printed. If, after stripping trailing slashes, string contains no slash at all, a single . is printed. If removing the last component leaves nothing but slashes, a single / is printed.

String is text, not a filesystem lookup: no file or directory named by string needs to exist, and none is opened.

/usr/man/DIRNAME this page

basename(1)

Exit status is 0 on success; 2 on a usage error (a number of operands other than one); 1 if the result would not fit dirname's own working buffer (96 bytes).

This is the POSIX single-operand form only; some other implementations accept more than one string and print one line per operand.

September 14, 2026 maux