如何find最大(在条目,而不是大小)ext4目录?

Ubuntu 10.04.3 LTS x86_64,我在/var/log/messages看到以下内容:

 EXT4-fs warning (device sda3): ext4_dx_add_entry: Directory index full! 

来自dumpe2fs的相关信息:

 Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Free blocks: 165479247 Free inodes: 454382328 Block size: 2048 Inode size: 256 

我已经阅读了一些其他问题,如ext3_dx_add_entry:目录索引已满 , rm位于具有数百万个文件的目录中 ; 那些让我觉得必须有一个目录中有大量的项目在某处。

由于它是一个相当复杂的目录组织,我有一个基本的问题:我怎么能find生成这些消息的目录?

下面的一行将给你列出每个目录中有多less个文件,并按前十sorting。 它将从你当前的工作目录recursion运行,所以我不build议你从/运行这个,除非你完全不知道大目录可能在哪里。

 find . -type f | awk '{dir=gensub(/(.+\/).+/,"\\1","g (file://1%22,%22g/)"); dir_list[dir]++} END {for (d in dir_list) printf "%s %s\n",dir_list[d],d}d' | sort -nr |head 

输出将类似于以下内容:

 [user@localhost ~]# find . -type f | awk '{dir=gensub(/(.+\/).+/,"\\1","g (file://1%22,%22g/)"); dir_list[dir]++} END {for (d in dir_list) printf "%s %s\n",dir_list[d],d}d' | sort -nr | head 2048 ./test19/ 2048 ./test18/ 2048 ./test17/ 2048 ./test16/ 2048 ./test15/ 2048 ./test14/ 2048 ./test13/ 2048 ./test12/ 2048 ./test11/ 2048 ./test10/ 

如果你对运行这样的一行代码有点小心,那么只需要search所有大小超过50k的目录。 再次发现将是你的朋友在这里:

 find ./ -type d -size +50k 

如果您有多个挂载点,那么df -i将帮助您缩小哪个挂载已经用完或已经用完inode。

在命令的-exec部分使用sh,你可以启动另一个shell,并在那里很好地运行你的命令。

找 。 -name“* .dat”-exec csh -c'echo -n $ 1; grep ID $ 1 | wc -l'{} {} \;

或者在我的情况下,当在目录中的文件计数。 我使用“ls -f”,因为它产生ls输出unsorted,这是显着更快的尝试sorting之前计数输出。

在目录名称和数目之间添加新行

find / somedir / some / dir -type d -print -exec sh -c'ls -f $ 1 / * | wc -l'{} {} \;

与目录名称和计数之间的选项卡

find / somedir / some / dir -type d -exec bash -c'echo -en“$ 1 \ t”; ls -f $ 1 / * | wc -l'{} {} \;

http://www.compuspec.net/reference/os/solaris/find/find_and_execute_with_pipe.shtml