[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find Command

From: Bob Proulx
Subject: Re: Find Command
Date: Thu, 11 Jan 2007 09:07:36 -0700
User-agent: Mutt/1.5.9i

On Mon, 18 Dec 2006 22:05:17 +0900 aforce ma wrote:
> When I try to use the command belows to delete empty
> directories,there always comes error messages,however the empty
> directory has been deleted already,Is this a Bug? or how can I do to
> make the error do not come?
> find -type d -empty -exec rm -rf {} \;

There are two problems with the above.  One is that you are deleting
directories from the top down and so any time that a directory is in
another directory you will get this error.  To fix this you need to
delete from the bottom up using the -depth option.  Secondly is that
since these are empty directories you should not need the 'rm -rf'
option.  That feels to dangerous to me to use here.  It feels safer to
use rmdir instead.

Try this instead.

  find /some/path -depth -type d -empty -print
  find /some/path -depth -type d -empty -exec rmdir {} \;

Some other alternatives that are more efficient.  With a newer version
of GNU find.

  find /some/path -depth -type d -empty -exec rmdir {} +

With older GNU find.

  find /some/path -depth -type d -empty -print0 | xargs -r0 rmdir


reply via email to

[Prev in Thread] Current Thread [Next in Thread]