dirname(C) 19 June 1992 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. It is normally used inside substitution marks (``) within shell procedures. 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), sh(C) Standards conformance dirname is conformant with: X/Open Portability Guide, Issue 3, 1989.