dirname(C) 06 January 1993 dirname(C) Name dirname - deliver directory part of pathname Syntax dirname string Description The dirname command delivers all but the last component of the pathname in string and prints the result on the standard output. If there is only one component in the pathname, only a ``dot'' is printed. If string con- sists entirely of slash characters a single slash is printed, unless string consists of exactly two slashes, in which case both are printed. It is normally used inside substitution marks (``) within shell pro- cedures. The companion command basename deletes any prefix ending in a slash (/) and the suffix (if present in string) from string, and prints the result on the standard output. Examples The following example sets the shell variable NAME to /usr/src/cmd: NAME=`dirname /usr/src/cmd/cat.c` This example prints /a/b/c on the standard output: dirname /a/b/c/d This example prints a ``dot'' on the standard output: dirname file.ext This example moves to the location of a file being searched for (lost- file): cd `find . -name lostfile -exec dirname ;` See also basename(C) and sh(C). Standards conformance dirname is conformant with X/Open Portability Guide, Issue 3, 1989.