# cd to a first sorted folder, exclude hidden
first() {
local first
first="$(
find . -mindepth 1 -maxdepth 1 -type d ! -name '.*' -printf '%f\n' \
| sort \
| head -n 1
)"
if [[ -z "$first" ]]; then
echo "no folders"
return 1
fi
cd "./$first"
}
2026-02-10
My new #bash alias: one function to go to the next folder (like from 2025 to 2026, from aaa to bbb) and the second one to #cd to prev:
cdn() {
local cur next
cur="$(basename "$PWD")"
next="$(
find .. -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
| sort \
| awk -v cur="$cur" '$1>cur{print; exit}'
)"
if [[ -z "$next" ]]; then
echo "no next folder"
return 1
fi
cd "../$next"
}
cdp() {
cur="$(basename "$PWD")"
prev="$(
find .. -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
| sort \
| awk -v cur="$cur" '$1<cur{p=$1} END{print p}'
)"
if [[ -z "$prev" ]]; then
echo "no previous folder"
return 1
fi
cd "../$prev"
}