(coreutils.info)dirname invocation


Next: pathchk invocation Prev: basename invocation Up: File name manipulation
Enter node , (file) or (file)node

18.2 `dirname': Strip non-directory suffix from a file name
===========================================================

`dirname' prints all but the final slash-delimited component of a
string (presumably a file name).  Synopsis:

     dirname NAME

   If NAME is a single component, `dirname' prints `.' (meaning the
current directory).

   Together, `basename' and `dirname' are designed such that if `ls
"$name"' succeeds, then the command sequence `cd "$(dirname "$name")";
ls "$(basename "$name")"' will, too.  This works for everything except
file names containing a trailing newline.

   POSIX allows the implementation to define the results if NAME is
`//'.  With GNU `dirname', the result is `//' on platforms where // is
distinct from /, and `/' on platforms where there is no difference.

   The only options are `--help' and `--version'.  Note: Common
options.

   An exit status of zero indicates success, and a nonzero value
indicates failure.

   Examples:

     # Output "/usr/bin".
     dirname /usr/bin/sort

     # Output ".".
     dirname stdio.h


automatically generated by info2www version 1.2.2.9