a script to remove empty directories

Igor Pechtchanski pechtcha@cs.nyu.edu
Thu Feb 19 21:34:00 GMT 2004


On Thu, 19 Feb 2004, Andreas Seidl wrote:

> Bruce Ingalls wrote:
>
> > Anyhow, here is an elegant, working solution. If no optional dir is
> > passed, then the current dir is checked recursively, and empty
> > subdirectories are passed.
> >
> > #!/bin/bash
> > ROOT=${1:-.}
> > if [ ! -d $ROOT ];then ROOT=.;fi
> > find $ROOT -type d -empty|xargs rmdir -f
>
> Meanwhile I was able to overcome the spaces in filenames problem, and,
> funny enough, i used wc -l as in the script posted by Volker for testing
> a directory to be empty. But I use recursion, which is bad for
> incorporation in other scripts. Anyway, below is, just for the records,
> my meanwhile obsolete solution.
>
> Your version is much faster (but has problems with spaces) than my
> version and the version posted by Volker. (e.g. 4s versus 50s).

Here's a variant of the above that works with spaces in filenames (but
doesn't delete directories that contain only empty directories):

find $ROOT -depth -type d -empty -print0 |xargs -0 rmdir -f

However, does anyone care to submit a patch to the generic-build-script?
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton



More information about the Cygwin-apps mailing list