commands

dirname — extract directory portion

Prints the directory portion of path text. A name without a slash normally produces a dot. It does not verify existence or resolve symlinks. Examples assume a fresh chapter files lab.

Formal Syntax & Structure

linux syntaxlinux
dirname NAME...

Parameters & Attributes

NameTypeDescription
NAMEoperandPath text

Return Value

text and exit status

Prints the directory portion of the supplied path text. GNU dirname returns 0 on successful processing; the resulting directory need not exist.

Working Example

Example Snippetlinux
dirname "notes/daily report.txt"
Linux Reference