dirname

Convert a full pathname to just a path.

Syntax
     dirname pathname

Print to standard output all but the final slash-delimited component of a string (presumably a filename) i.e. Delete the filename portion.

If pathname is a single component, dirname prints . (meaning the current directory)

Examples

Set the shell variable FOO to /usr/bin:

FOO=`dirname /usr/bin/trail`

Extract the path from the variable pathnamevar and store in the variable result using parameter expansion $( )

$ result=$(dirname "$pathnamevar")

"How beautiful the leaves grow old. How full of light and color are their last days” ~ John Burroughs

Related Linux commands

basename – Strip directory and suffix from filenames.
hash - Remember the full pathname of a name argument.
ls - List information about File(s).
which - Show full path of commands.
Equivalent Windows command: SET Parameters - get a full or partial pathname from a variable.


 
Copyright © 1999-2024 SS64.com
Some rights reserved