Another one: cdof () { cd "$(dirname $1)" } as in 'Change into Directory Of" Changes into the directory of a file. This is useful when you're doing complicated commands with long path names, but realize it would be easier if you were to cd into that directory. Use in combination with . Especially useful if the filename component is long: $ pwd => ~/ $ ls -l path/to/whatever/deep/somewhere/2021-04-22-filewithverylongn…
function cd() {
if [[ ${#} -eq 0 ]]; then
builtin cd
return
fi
if [[ -f ${1} ]]; then
builtin cd $(dirname ${1})
else
builtin cd ${1}
fi
}