我有一堆嵌套的文件夹。 大多数文件夹包含文件 有些包含数十万个文件。 有些是空的。
我想获得所有空文件夹的列表。 但是,当我运行:
find -type d -empty
运行需要很长时间,比运行find -type d要花费很多时间。 我怀疑-empty正在检查所有文件,看它们是否为空,然后-type d正在跳过这些文件。
那么在那里:
1)一种优化发现的方法,以便它将a)find所有的文件夹,然后b)列出空的那些?
要么
2)一个不同的命令(或命令),我可以用来得到这个列表?
尝试这个
find / -xdev -type d -exec find {} -maxdepth 0 -empty \;
或者稍微快一些
find / -xdev -type d | xargs -I{} find {} -maxdepth 0 -empty
find -type d | xargs -I{} find {} -empty
刚刚testing过,我不能得到你的结果:
japhy@lizard:~ % time find . -type d |wc -l 48403 find . -type d 0.87s user 8.69s system 4% cpu 3:37.60 total japhy@lizard:~ % time find . -type d -empty |wc -l 3986 find . -type d -empty 0.79s user 4.41s system 57% cpu 9.071 total japhy@lizard:~ % time find . -empty -type d |wc -l 3986 find . -empty -type d 0.70s user 3.32s system 98% cpu 4.085 total japhy@lizard:~ % find --version find (GNU findutils) 4.4.2 Copyright (C) 2007 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Eric B. Decker, James Youngman, and Kevin Dalley. Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX FTS() CBO(level=0)
你的“find”工具的版本是什么? 发行版本?
那些find的参数并不是以任何顺序解释的开关,find是一个命令行处理器,每一个东西都是一个按顺序运行的testing。 你的命令行按照你指定的顺序执行:find目录,然后检查它们是否为空。 我不认为有任何诀窍涉及到更快地做到这一点。