1823753 Members
3972 Online
109664 Solutions
New Discussion юеВ

HP-UX empty directories?

 
Brad Edwards
New Member

HP-UX empty directories?

I'm doing some scripting on an HP-UX system, and one of the checks I'd like to make is to check whether a directory is empty or not. However, I've encountered some strange behavior. As I understand it, most Unix's implement the directory filetype as a binary listing (one per line) of the items contained therein, correct? A typical empty directory should then be 96 (for HP-UX only) bytes. As the number of files increases in the directory, the size of the directory itself should also grow, correct? On HP-UX systems, however, I've been finding several directory names that have somewhat large sizes (13K), and yet are still empty; `ls -al` says 'total 0'. When I run the `strings` command on the directory names I get a listing of several older files that are no longer in the directory. Any idea why the directory name isn't clearing the names out of itself as the files are deleted? Is this normal?
3 REPLIES 3
Chris Wilshaw
Honored Contributor

Re: HP-UX empty directories?

Yes, this is normal behaviour. Under HP-UX, the directory size can increase, but not decrease.

If you do a search on the forums, for "empty directory size", you should be able to pick up more details (unfortunately, when I try at the moment, I get an "unable to log in" message, as it's trying to point me to the US site).
Ceesjan van Hattum
Esteemed Contributor

Re: HP-UX empty directories?

So, better to write a new script, like:

for i in `find . -type d -exec ls -d {} \;`
do
size=`ls -la $i | wc -l`
let size=size-3
if [ $size -eq 0 ]
then
echo "empty dir : $i
fi
done

Regards,
Ceesjan
Wodisch_1
Honored Contributor

Re: HP-UX empty directories?

Hi,

UN*X (any flavour of) cannot shrink directories. And file-entries in a directory are *deleted* by assigning the reserved inode-number 0 to them, so the names stay in there - until they are overwritten by a new file-entry.

So, to find *empty* directories you will have to check wether they only contain "." and ".." and nothing more!

HTH,
Wodisch