Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

dirname - return directory portion of pathname

&pagelevel(4)&pagelevel

dirname can be used to strip the file name (basename) from the full access path. dirname takes a string as its argument, removes the final slash and all characters to the right of it, and writes the rest of the string on standard output. dirname is useful in shell scripts.


Syntax


dirname[ string]

string

string can be any string of characters.

dirname deletes the final slash and all characters to the right of it and writes the remaining portion to standard output. If string does not contain a slash, a dot is written to standard output.

string not specified:
a dot is written to standard output.

Locale

The following environment variables affect the execution of dirname:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example

In the following example, the path prefix /usr/src/cmd is assigned as a value to the NAME variable:

NAME=`dirname /usr/src/cmd/xyz.c`

See also

basename, ed