Hi Patrick,

I am interested in the example you provided and looking at the IBM
documentation for find I do not see the -depth option as being available.

https://www.ibm.com/docs/en/ssw_ibm_i_72/rzahz/rzahzpdf.pdf

I just ran part of the example;
find -depth -type d
find: 001-3026 usage: find [-H | -L | -P] [-Xdx] [-f file] file ...
[expression]

I have a large number of empty directories and this would be very useful.

How should I be running this ?

Thanks

Don






From: "Patrik Schindler" <poc@xxxxxxxxxx>
To: "Midrange Systems Technical Discussion"
<midrange-l@xxxxxxxxxxxxxxxxxx>
Date: 02/10/2021 08:41 PM
Subject: Re: Finding empty folders on IFS and QSH find
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx>



Hello K.,

Am 01.10.2021 um 17:41 schrieb K Crawford <kscx3ksc@xxxxxxxxx>:

This works. find /home/kcrawford -type d

I am open to other solutions.

A simple shell-script will do also. I assume there are no blanks in the
directory names!

Here, find generates a list of all directories starting from the current
directory, listing the most nested directories first (so directories
freeing directories can be probably identified as free, and deleted). For
every entry, a "ls" command prints *all* entries, line by line. An empty
directory has only two lines, two entries for . and .., so it's safe to
assume that a directory with only two entries is empty and can be safely
removed.

for DIR in `find . -depth -type d`; do
if [ `ls -1a ${DIR} |wc -l` -eq 2 ]; then
rmdir ${DIR}
fi
done

Tested in qsh with 7.2, no error messages. Can be used as one-liner, or
saved in a *STMF with indents to help understanding at a later point in
time. :-)

Important! The backticks are *not* apostrophes! You may see these like a
braced expression in mathematics.

:wq! PoC


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.