dirname

From RaySoft

dirname prints all but the final slash-delimited component of each NAME. Slashes on either side of the final component are also removed. If the string contains no slash, dirname prints . (meaning the current directory).[1]

Documentation

Syntax

dirname NAME

Examples

Remove the file
dirname "${HOME}/tmp/test.txt"

Output:

/home/alex/tmp
Replace dirname using Bashism
file="${HOME}/tmp/test.txt"

echo "${file%/*}"

Output:

/home/alex/tmp

References