Dr. Volker Zell wrote:

Here is another one from

o http://www.shelldorado.com/scripts/categories.html

I searched with Google, but did not find it...


----------- cut here -------------------------------
:
# rmemptydir - remove empty directories
# Heiner Steven ([EMAIL PROTECTED]), 2000-07-17
#
# Category: File Utilities

[ $# -lt 1 ] && set -- .

find "$@" -type d -depth -print |
    while read dir
    do
        [ `ls "$dir" | wc -l` -lt 1 ] || continue
        echo >&2 "$0: removing empty directory: $dir"
        rmdir "$dir" || exit $?
    done
exit 0
----------- cut here -------------------------------

This is the best one we have seen today. The clever -depth option to find ensures, that directories, which contain only empty directories, are removed as well:


$ find . -type d -depth -print
./asd
./asdf asdf/jkl
./asdf asdf
./usr/bin
./usr
.

as opposed to:

$ find . -type d -print
.
./asd
./asdf asdf
./asdf asdf/jkl
./usr
./usr/bin





Reply via email to