![]() |
![]() |
![]() |
Return directory portion of pathname (POSIX)
dirname string
The dirname utility returns a portion of the string operand to standard output. The string operand represents a valid pathname whose format is:
The dirname utility writes the directory_pathname component to standard output.
If string is //, then // is returned. Any other string consisting entirely of slash characters causes a single slash to be returned.
You usually use the dirname utility inside command substitution marks, $(...), within shell procedures.
| Command: | Output: |
|---|---|
| dirname . | . |
| dirname .. | . |
| dirname ../. | .. |
| dirname /usr/src/prog.c | /usr/src |
| dirname /usr/src/ | /usr |
| dirname ...//[fred] | ... |
The dirname utility writes the directory name string derived from the command-line parameters to its standard output.
![]() |
![]() |
![]() |