The dirname command in Bash

dirname is a UNIX-like OS program designed to convert an absolute or relative path to a file or directory into the name of the parent directory.

Syntax

dirname string
  • string - path to file or directory

Example

$ dirname ~/tests/1.txt
/home/alimektor/tests