This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a script to remove empty directories


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 (heiner.steven@odn.de), 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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]