basename
basename removes any leading directory components from NAME.[1]
If SUFFIX is specified and is identical to the end of NAME, it is removed from NAME as well.[1]
- GNU Coreutils [EN] @ Fedora Package
- GNU Coreutils [EN] @ Homebrew Formula
Documentation
- basename [EN] @ GNU Coreutils Manual
- man 1 'basename' [EN]
Syntax
basename NAME [SUFFIX]
Examples
- Remove the directories
basename "${HOME}/tmp/test.txt"
Output:
test.txt
- Replace basename using Bashism
file="${HOME}/tmp/test.txt"
echo "${file##*/}"
Output:
test.txt