utility

dirname

Print the directory portion of a pathname; no existence check. GNU supports --.

Formal Syntax & Structure

bash syntaxbash
dirname [OPTION] NAME ...

Parameters & Attributes

NameTypeDescription
pathstringFile or path operand; quote shell expansions.

Return Value

exit status

Exit status 0 on success; nonzero indicates failure or a command-specific condition. See description and example.

Working Example

Example Snippetbash
path='reports/daily report.txt'basename -- "$path"dirname -- "$path"
Bash Reference