From owner-freebsd-questions Sat Jul 27 09:45:10 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id JAA20100 for questions-outgoing; Sat, 27 Jul 1996 09:45:10 -0700 (PDT) Received: from sam.networx.ie (dublin-ts12-242.indigo.ie [194.125.133.242]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id JAA20091 for ; Sat, 27 Jul 1996 09:45:06 -0700 (PDT) Received: from mip1.networx.ie (mip1.networx.ie [194.9.12.1]) by sam.networx.ie (8.6.12/8.6.12) with SMTP id RAA26782; Sat, 27 Jul 1996 17:41:14 +0100 X-Organisation: I.T. NetworX Ltd X-Business: Network Consultancy and Training X-Address: 67 Merrion Square, Dublin 2, Ireland X-Voice: +353-1-676-8866 X-Fax: +353-1-676-8868 Received: from mike.networx.ie by mip1.networx.ie Date: Sat, 27 Jul 1996 17:32:42 BST From: Michael Ryan Reply-To: mike@NetworX.ie Subject: Re: Deleting a Link Farm To: Marc Ramirez Cc: Annelise Anderson , freebsd-questions@freebsd.org Message-Id: Priority: Normal Mime-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 ---