buildsolarisaix

Unix: fast 'remove directory' for cleaning up daily builds


Is there a faster way to remove a directory then simply submitting

rm -r -f *directory*

? I am asking this because our daily cross-platform builds are really huge (e.g. 4GB per build). So the harddisks on some of the machines are frequently running out of space.

This is namely the case for our AIX and Solaris platforms.

Maybe there are 'special' commands for directory remove on these platforms?

PASTE-EDIT (moved my own separate answer into the question):

I am generally wondering why 'rm -r -f' is so slow. Doesn't 'rm' just need to modify the '..' or '.' files to de-allocate filesystem entries.

something like

mv *directory* /dev/null

would be nice.


Solution

  • For deleting a directory from a filesystem, rm is your fastest option. On linux, sometimes we do our builds (few GB) in a ramdisk, and it has a really impressive delete speed :) You could also try different filesystems, but on AIX/Solaris you may not have many options...

    If your goal is to have the directory $dir empty now, you can rename it, and delete it later from a background/cron job:

    mv "$dir" "$dir.old"
    mkdir "$dir"
    # later
    rm -r -f "$dir.old"
    

    Another trick is that you create a seperate filesystem for $dir, and when you want to delete it, you just simply re-create the filesystem. Something like this:

    # initialization
    mkfs.something /dev/device
    mount /dev/device "$dir"
    
    
    # when you want to delete it:
    umount "$dir"
    # re-init
    mkfs.something /dev/device
    mount /dev/device "$dir"