On Unix-like operating systems, the dirname command strips the last part of given file name, outputting the complete pathname of the directory where the file is located.

This page covers the GNU/Linux version of 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).

  • Description
  • Syntax
  • Examples
  • Related commands
  • Linux commands help

Examples

dirname /usr/bin

Returns:

/usr

dirname stdio.h

.

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