Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help replacing -exec in find call with xargs

3 views
Skip to first unread message

Melroy

unread,
Oct 20, 2009, 12:04:21 AM10/20/09
to
Hi,
I have a find call as follows
find . -depth -type d -empty -exec ls -ld {} \; -exec rmdir {} \;
I want to replace this with xargs to speed it up . However how do I
ensure that the filename is also printed
What I could come up with is as follows
find . -depth -type d -empty -print | xargs rmdir
However this does not print the directories as it removes them.
how do I do this? Its probably simple. but can't seem to figure it
out.
Thanks

Marcel Bruinsma

unread,
Oct 20, 2009, 3:20:39 AM10/20/09
to
Am Dienstag, 20. Oktober 2009 06:04, Melroy a écrit :

> find . -depth -type d -empty -exec ls -ld {} \; -exec rmdir {} \;
> I want to replace this with xargs to speed it up.

Perhaps, not with xargs, but with sh:

find . -depth -type d -empty -exec sh -c '
ls -ld "$@";rmdir "$@"' sh {} +

--
printf -v email $(echo \ 155 141 162 143 145 154 142 162 165 151 \
156 163 155 141 100 171 141 150 157 157 056 143 157 155|tr \ \\\\)
# Live every life as if it were your last! #

Stephane CHAZELAS

unread,
Oct 20, 2009, 12:11:52 PM10/20/09
to
2009-10-20, 09:20(+02), Marcel Bruinsma:
> Am Dienstag, 20. Oktober 2009 06:04, Melroy a ᅵcrit :

>
>> find . -depth -type d -empty -exec ls -ld {} \; -exec rmdir {} \;
>> I want to replace this with xargs to speed it up.
>
> Perhaps, not with xargs, but with sh:
>
> find . -depth -type d -empty -exec sh -c '
> ls -ld "$@";rmdir "$@"' sh {} +

You could as well do:

find . -depth -type d -empty -exec ls -ld {} + \
-exec rmdir {} +

And if your find has the non-standard -empty predicate, it also
probably has the -ls one.

The initial solution only calls rmdir if ls -ld succeeds,
so the equivalent using sh would be:

find . -depth -type d -empty -exec sh -c '

for i do
ls -ld "$i" && rmdir "$i"
done' sh {} +

(which is no speed up, unless your sh has ls or rmdir built in).

--
Stᅵphane

0 new messages