From a092c148627a04dee0839d0265fd844f50475351 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Wed, 29 May 2019 11:59:38 +0100 Subject: [PATCH] bin: add `delete-all` to find and delete `delete-me` directories Signed-off-by: Alejandro Mery --- files/bin/delete-all | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 files/bin/delete-all diff --git a/files/bin/delete-all b/files/bin/delete-all new file mode 100755 index 0000000..f1f418f --- /dev/null +++ b/files/bin/delete-all @@ -0,0 +1,25 @@ +#!/bin/sh + +if [ $# -eq 0 ]; then + set -- "$HOME/projects" +fi + +find_delete_me() { + local depth="$1" x= + shift + + for x; do + if [ ! -e "$x" ]; then + : + elif [ "${x##*/}" = "delete-me" ]; then + echo "$x" + elif [ $depth -gt 0 ]; then + find_delete_me $(( depth - 1 )) "$x"/* + fi + done +} + +find_delete_me 4 "$@" | while read x; do +echo "# $x" +rm -rf "$x" +done