🎃 Valiukas

jump to main content

bash: loop over directories

Sep 18, 2022

From stackoverflow:

for dir in /tmp/*/     # list directories in the form "/tmp/dirname/"
do
    dir=${dir%*/}      # remove the trailing "/"
    echo "${dir##*/}"    # print everything after the final "/"
done