Getting the parent of a directory in Bash September 30, 2022 by Tarik dir=/home/smith/Desktop/Test parentdir="$(dirname "$dir")" Works if there is a trailing slash, too.