TrumanWong

dirname

Remove non-directory parts of filenames

Supplementary instructions

dirname command removes the non-directory part of the file name and displays only the content related to the directory. The dirname command reads the specified pathname keeping the last / and the following characters, deletes other parts, and writes the result to standard output. If there are no characters after the last /, the dirname command uses the second to last / and ignores all characters after it. dirname and basename are commonly used within shell command substitution to specify an output file name that differs slightly from the specified input file name.

grammar

dirname(option)(parameter)

Options

--help: display help;
--version: Display version number.

Example

dirname //
The result is /

dirname /a/b/
The result is: /a

dirname a
The result is .

dirname a/b
The result is pathname a