#!/bin/sh recursive() { pwd # your command here for d in *; do if [ -d "$d" ]; then (cd -- "$d" && recursive) fi done } recursive