#!/bin/sh # merge directory contents with its parent directory. # duplicates are renamed. unique_path() { old="$1" new="$1" counter=0 while test -e "$new" do counter=$(($counter + 1)) new="$old.$(($counter + 1))" done printf "$new" } for a in "$@" do if test -d "$a" then for b in "$a"/* "$a"/.* do name="$(basename "$b")" if ! echo "$name" | grep -qE '(\.|\.\.|\*)$' then target="$(unique_path "$a/../$name")" mv "$b" "$target" fi done rmdir "$a" fi done