Date: Sat, 27 Jul 1996 17:32:42 BST From: Michael Ryan <mike@NetworX.ie> To: Marc Ramirez <mrami@mrami.com> Cc: Annelise Anderson <andrsn@andrsn.stanford.edu>, freebsd-questions@freebsd.org Subject: Re: Deleting a Link Farm Message-ID: <ECS9607271742B@NetworX.ie>
next in thread | raw e-mail | index | archive | help
I think the following will do what you want. Enjoy. ---8<---cut-here---8<--- #! /bin/sh -- # # Remove all empty directories in the list of directories # supplied. If a directory which is empty is a sub-directory # of a directory with nothing but that sub-directory in it, # the parent directory gets deleted also. # # The -symlink flag causes directories with only symbolic # links in them to also be deleted. # # # MikeRyan, 26jul96. # Remove symlinks only. rm_symlinks () { find $* -type l -print | xargs rm -f } # Remove empty directories in an inverse-recursive way. rm_edirs () { find $* -depth -type d -print | while read dir; do nfiles=`ls -lA $dir | egrep -v '^total ' | wc -l` test $nfiles -eq 0 && { echo Removing $dir rmdir $dir } done } test $# -eq 0 && { echo Usage: rmedir dir ... exit 1 } test "$1" = -symlink && { shift rm_symlinks $* } rm_edirs $* exit 0 ---8<---cut-here---8<--- On Sat, 27 Jul 1996 11:18:03 -0400 (EDT) Marc Ramirez wrote: > > Is there an easier way, or a way to remove only empty directories and > > leave those with regular files? > > find /usr/ports -type l -exec rm {} \; > > will delete all symbolic links. Mike <mike@NetworX.ie> ---
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ECS9607271742B>