#!/bin/bash # This Script is Licensed by GPL3 or Higher # Author Angel Berlanas Vicente # # FUNCTIONS # _die(){ echo -e "$1" >&2 exit 1 } _usage() { CMD_NAME="$(basename "$0")" _die "Usage: $CMD_NAME PATH_FIND_EMPTY_DIRECTORIES \n Usage: STDIN |$CMD_NAME - \n" } _find_empty_directories_and_remove_them(){ if [ -d $1 -a -w $1 -a -x $1 ]; then find "$1" -mindepth 1 -maxdepth 1 -empty -xtype d -exec rm -rf {} \; 2>/dev/null return 0 else return 0 fi } # # MAIN # [ $# -ne 0 -a "$1" != "-" ] || exec xargs $0 for f in "$@" ; do [ "$f" = "-" ] || _find_empty_directories_and_remove_them "$f" done exit 0