You are here: >

Linux and Unix dirname command

dirname commandAbout dirname
dirname syntax
dirname examples
Related commands
Linux and Unix main page

About dirname

The dirname command strips the last part of a given filename, in effect outputting just the directory components of the pathname.

dirname syntax

dirname [OPTION] NAME...

Description

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

-z, --zero separate output with NUL rather than a newline.
--help Display a help message and exit.
--version Display version information and exit.

dirname examples

dirname /usr/bin

Returns:

/usr
dirname stdio.h

Returns:

.

basename — Strip directory information and suffixes from filenames.
expr — Evaluate arguments as an expression.