Operating System - HP-UX
1823914 Members
3251 Online
109667 Solutions
New Discussion юеВ

Re: Delete Empty directories

 
SOLVED
Go to solution
DavidJ
Regular Advisor

Delete Empty directories

Hi

Does anyone out there have a script which does a search and distroy for empty directories on your system?

The -empty option is not valid for "find" on HP-UX ;-(

tia
Everyday I beat my own previous record for number of consecutive days I've stayed alive.
6 REPLIES 6
Yarek
Regular Advisor

Re: Delete Empty directories

hi,


Please try to use 'rmdir' - remove empty directories


rgds

Peter Godron
Honored Contributor
Solution

Re: Delete Empty directories

David,
please see:
http://duramecho.com/ComputerPrograms/DeleteEmptyDirectories/index.html

You can try the Perl sulution on a TEST filesystem. Seemed to work for me !

Or download gnu find and use the -empty option.

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.


Peter Godron
Honored Contributor

Re: Delete Empty directories

David,
bit slow at work here, so I put together this script. It may still need some fine tuning, so please test it first !

#!/usr/bin/sh
# Pull out a list of all directories
find . -depth -type d > /tmp/x.x
while read direc
do
# count the number of files in each directory
count=`ll -1a $direc | wc -l`
echo $direc $count
if [ $count -eq 3 ]
then
rmdir $direc
fi
done < /tmp/x.x
rm /tmp/x.x
DavidJ
Regular Advisor

Re: Delete Empty directories

Thanks Peter, I have similar shell script but was looking for something more 'eligant' and the perl script just did the trick. ;-) Ta
Everyday I beat my own previous record for number of consecutive days I've stayed alive.
Dennis Handly
Acclaimed Contributor

Re: Delete Empty directories

It seems you can just use find and rmdir and ignore the zillions of errors. I'm not sure if it is worth Peter's checking script:

find some-path -depth -type d -exec rmdir + 2>&1 | \
grep -v "rmdir.*Directory not empty"
DavidJ
Regular Advisor

Re: Delete Empty directories

Thanks All

The Perl script fits the bill perfectly.

perl -MFile::Find -e"finddepth(subrmdir},'.')"
Everyday I beat my own previous record for number of consecutive days I've stayed alive.