#!/bin/bash
# /usr/local/bin/no_recurse
# https://crystalfaeries.net/posix/bin/no_recurse
# celeste:crystalfaery NO_RECURSE 2017-07-30 20:53:40+00:00
# no_recurse removes recursively embedded folders and/or symlinks
if [ $# -ne 0 ]
then # argumentative user, eh?
case "${1}" in
-h | --help)
echo "`basename $0` accepts an optional argument of working_directory, else works in current_directory."
exit 0
;;
-v | --version)
tail -n +4 $0 | head -n 1 # lazy damn hacker...
exit 0
;;
*)
cd "${1}" || exit 1 # change working directory or fail
shift # pedantically politically correct
if [ $# -ne 0 ]
then # excessively argumentative user
echo "`basename $0` accepts ONLY 1 optional argument of working_directory, until you extend the code..."
exit 1
fi # we won the argument by failing :-)
;;
esac
fi # finished arguing
nice ionice -c 3 find . -type d | \
while read dirpath
do
ls -d "${dirpath}"/"$(basename ${dirpath} 2>/dev/null)" 2>/dev/null
done | xargs rm -rf 2>/dev/null # remove recursive hierarchy
exit # pau
syntax highlighted by Code2HTML, v. 0.9.1