a question for you shell scripters
Kevin Hodle
kevinh at aos5.com
Wed Mar 26 15:30:18 CST 2003
If you ask me, the 'right' way would be witchever way works :)
... But, if you wanted a snippet of shell code, here you go
ls /whatever > test.dir
if [ -s test.dir ]; then
# directory has stuff in it
else
#directory is empty, you can rm -rf it
Frankly, your original method seems fine for your needs.
Kevin Hodle
CCNA, Network+, A+
Alexander Open Systems
Network Operations Center
kevinh at aos5.com
-----Original Message-----
From: Jason Clinton [mailto:clintonj at umkc.edu]
Sent: Wednesday, March 26, 2003 9:22 AM
To: kclug
Subject: a question for you shell scripters
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.
--
Jason Clinton
I don't believe in witty sigs.
More information about the Kclug
mailing list