a question for you shell scripters
Monty J. Harder
lists at kc.rr.com
Thu Mar 27 02:58:26 CST 2003
"Jason Clinton" <clintonj at umkc.edu> wrote:
> How can I rmdir all subdirectories that have no files in them,
> recursively. For instance: I have a music directory with artist
> subdirectories with album directories beneath that. Over the course of
> time, I have asked XMMS to delete a song I'm tired of hearing. I've
> found that there are not artists that I have no songs remaining for so
> their entire directory structure is just a bunch of empty folders.
>
> I came up with this newbish solution:
>
> # rmdir */*
> # rmdir *
>
> This works fine (since rmdir will only delete empty stuff) from the
> music directory and if I don't have lots of subdirectories, but I'm
> wondering what the /right/ way to do it is.
Well, "There's More Than One Way To Do It" <tm Larry Wall> but here's
probably how I would do it:
find . -empty -type d | xargs -i rmdir {}
That will descend the directory tree to any arbitrary depth, and not even
TRY to remove anything but an empty directory.
More information about the Kclug
mailing list