Shell script for recursive delete required.

By | December 8, 2017

rajeshkumar created the topic: Shell script for recursive delete required.

#!/bin/bash

if [ $# -ne 1 -o ! -d "$1" ]
then
echo "Usage $0 dirname"
exit 1
fi

find "$1" -type f -print | while read file
do
dir=$(dirname "$file")
dname=$(basename "$dir")
fname=$(basename "$file")
[ "$dname" = "$fname" ] && rm "$file"
done

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Leave a Reply