[Klug-general] Bash script to delete folders if they exists (revisited)

Nathan Friend nathan.friend at gmail.com
Fri Jul 15 17:19:56 UTC 2011


Afternoon KLUG,
Last year I wanted a bash script to delete folders if they existed in
a predefined list file.  The end result was:

while read dir
do
if [ -d $dir ]
then
rm -R $dir
echo "Directory $dir found and deleted."
else
echo "Directory $dir not found."
fi
done < dir_list


dir_list file contains
/Users/user1
/Users/user2
/Users/user3

This year I need to delete all files in the /Users/ folder except the ones
listed in dir_list.

Any ideas?

Cheers,

Nathan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/kent/attachments/20110715/cdd59968/attachment.htm>


More information about the Kent mailing list