#!/bin/sh clean_dir() { local dir="$1" if [ -d "$dir" ]; then find "$dir" -name "*~" -print -delete find "$dir" -name ".*~" -print -delete find "$dir" -name "#*#" -print -delete else echo "$dir: not a directory" >&2 fi } if [ $# -ne 0 ]; then for dir in "$@"; do clean_dir "$dir" done else clean_dir "./" fi