[b]#!/bin/sh
#
# Leave this as period, this means you must place both this script and the text file #in /mnt/db directory
HighLevelDir=".";
#
# Replace the flist.txt with the name of the #file that will contain the list of files. #This must reside in the same directory as
# the script at the very same level.
#
for FileToCheckFor in `cat flist.txt`
do
WorkVar="${FileToCheckFor}*";
echo "ding ding ding find $HighLevelDir -type d -name $WorkVar -print";
for DirFound in `find $HighLevelDir -type d -name "$WorkVar" -print`
do
echo "foudn $DirFound";
if [ -e "${DirFound}/$FileToCheckFor" ]
then
#
# When after running this with these echo's in it, and you feel
#that it is only finding files you want.
# uncomment the rm line
echo "wack goes directory ${DirFound}"
#`rm -rf ${DirFound}`
fi
done
done[/b]
---------------------------------------------
for some bloody reason, I couldn't get the damn find to work any other way then placing it in the /mnt/db directory. I tested this against 3 directories. The file contained 2 lines representing the files I was looking for.
111111
222222
File 111111 was placed in two directories, and the file 222222 was placed in one. Each of these directories were deleted with this script. I also tested this script with some files not being found, and only the directories that I expected to be deleted did.
The logic of this script is as follows.
High level loop reads your file line by line. It then use's what is in that line to perform the find command from the current directory structure down looking for directory names that have the qualifier of the file name in it. This is in a loop in case your file is in multiple directories. The directory is not deleted unless the file is actually in it.
Run this, test this. If you have any problems with it. Private message me, I'll remove the block from my profile so that you can.
I don't know how well this will hold up to thousands of files, or how long it will run. And I apologize for the sloppiness of the script, I have done better. But, it should work.
roflmao, and for gods sakes. Please forgive my echo statements... They were put in for echoing variables so I could see what was being built into them. I just have a tendency to be ummmm, unorthodox in the way I do these types of displays.
Dan