#!/usr/bin/env bash NAME="$(basename "$0")" FROM="$1" TO="$2" usage() { printf "Usage: %s from to\n" "$NAME" printf "from The directory to copy from.\n" printf "to The directory to copy to.\n" } if [[ ! -d "$FROM" ]]; then usage exit 1 fi if [[ ! -d "$TO" ]]; then usage exit 1 fi for i in {1..9}; do if [[ ! -e "$TO/man$i" ]]; then mkdir "$TO/man$i" fi find "$FROM" -type f -name "*.$i" | xargs -I {} cp {} "$TO/man$i" done