开发者

Remove empty directories in AIX

Is there an easy开发者_JS百科 way to find and remove all empty directories under a specific path? Since -empty is not available in AIX find command


See this link or this link for possibilities.

Also can you use GNU find, installed as part of the linux toolbox in /opt/freeware/bin/find or /usr/linux/bin/find? For one offs, I use them quite often on AIX5.2+. As part of a script or tool I wouldn't rely on them however...


The question applies to all versions of UNIX that don't support the (non-standard) "-empty" qualifier.

The first link in the answer above mentions the "-exec" options, however that would require a fork() / exec() for each and every directory, which can be a bit much. A far easier solution would be to use xargs and rmdir. One caveat -- if there are files with special characters in the file name, it can confuse xargs if you don't use the "-print0" option to "find" and the "-0" option to "xargs".

A better and faster solution would be

find -type d -depth -print0 | xargs --null rmdir

assuming your "find" and "xargs" commands support the non-standard options that are given.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜