DIRNAME(1) User Commands DIRNAME(1)

# [NAME](#NAME)

dirname - strip last component from file name

# [SYNOPSIS](#SYNOPSIS)

**dirname** \[*OPTION*] *NAME*...

# [DESCRIPTION](#DESCRIPTION)

Output each NAME with its last non-slash component and trailing slashes removed; if NAME contains no /'s, output '.' (meaning the current directory).

[**-z, --zero**](#z,)

end each output line with NUL, not newline

[**--help**](#help)

display this help and exit

[**--version**](#version)

output version information and exit

# [EXAMPLES](#EXAMPLES)

[dirname /usr/bin/](#dirname)

-&gt; "/usr"

[dirname dir1/str dir2/str](#dirname~2)

-&gt; "dir1" followed by "dir2"

[dirname stdio.h](#dirname~3)

-&gt; "."

# [AUTHOR](#AUTHOR)

Written by David MacKenzie and Jim Meyering.

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to: &lt;bug-coreutils@gnu.org&gt;.  
Report any translation bugs to: &lt;https://translationproject.org/team/&gt;.  
GNU coreutils home page: &lt;https://www.gnu.org/software/coreutils/&gt;  
General help using GNU software: &lt;https://www.gnu.org/gethelp/&gt;

# [COPYRIGHT](#COPYRIGHT)

Copyright © 2026 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later &lt;https://gnu.org/licenses/gpl.html&gt;.  
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

# [SEE ALSO](#SEE_ALSO)

[**basename**(1)](/man/os/coreutils/basename.1), [**readlink**(1)](/man/os/coreutils/readlink.1)

Full documentation &lt;https://www.gnu.org/software/coreutils/dirname&gt;  
or available locally via: info '(coreutils) dirname invocation'

October 2026 GNU coreutils 9.12

---

Document: dirname(1) from coreutils 9.12-r4 (Chainguard OS)
Source: https://git.savannah.gnu.org/git/coreutils.git
