dirname strips off the trailing part of a file name. The result is the path name of the directory that contains the file. This is useful in shell scripts.
dirname makes no attempt to validate the path name; for validation, use the pathchk command.
dirname follows these rules:
- If pathname is not specified, return a single period (.).
- If pathname is //, return one slash
- If there are no slashes remaining in pathname, return period (.)
On Windows systems, these rules handle forward slashes in the same way as backslashes.
dirname returns device names as you type them in pathname -- if you include a slash, dirname returns the device name with the following slash; if you don't include a slash, the device name is returned with no following slash.
Possible exit status values are:
dirname is provided as both an external utility and a built-in MKS KornShell utility.
POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems. Windows 7. Windows Server 2008 R2. Windows 8. Windows Server 2012. Windows 10. Windows Server 2016. Windows Server 2019.
On Windows systems, dirname removes the final backslash or slash and all following characters. On UNIX and POSIX-compliant systems, backslash is a valid file name character and is not stripped.
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.2 Documentation Build 28.