dirname
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]
- GNU Coreutils [EN] @ Homebrew Formula
Documentation
- dirname [EN] @ GNU Coreutils Manual
- man 1 'dirname' [EN]
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