#!/bin/bash parent=$1 hasdirs=true while [ $hasdirs == true ] do for child in $(ls $parent) do if [ -d $parent/$child ] then mv $parent/$child/* $parent/ rmdir $parent/$child 2> /dev/null fi done hasdirs=false for child in $(ls $parent) do if [ -d $parent/$child ] then hasdirs=true break fi done done