(coreutils.info.gz) dirname invocation
Info Catalog
(coreutils.info.gz) basename invocation
(coreutils.info.gz) File name manipulation
(coreutils.info.gz) pathchk invocation
18.2 'dirname': Strip last file name component
==============================================
'dirname' prints all but the final slash-delimited component of each
NAME. Slashes on either side of the final component are also removed.
If the string contains no slash, 'dirname' prints '.' (meaning the
current directory). Synopsis:
dirname [OPTION] NAME...
NAME need not be a file name, but if it is, this operation
effectively lists the directory that contains the final component,
including the case when the final component is itself a 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 program accepts the following option. Also see Common
options.
'-z'
'--zero'
Separate output items with NUL characters.
An exit status of zero indicates success, and a nonzero value
indicates failure.
Examples:
# Output "/usr/bin".
dirname /usr/bin/sort
dirname /usr/bin//.//
# Output "dir1" followed by "dir2"
dirname dir1/str dir2/str
# Output ".".
dirname stdio.h
Info Catalog
(coreutils.info.gz) basename invocation
(coreutils.info.gz) File name manipulation
(coreutils.info.gz) pathchk invocation
automatically generated by
info2html