在Linux中,如何查找包含大多数子目录或文件的查找目录?

时间:2022-06-21 04:47:05

How can I find the directory with the largest number of files/subdirectories in it on the system? Obviously the clever answer is /, but that's not what I'm looking for.

如何在系统中找到包含最多文件/子目录的目录?显然,聪明的答案是/,但这不是我想要的。

I’ve been told the filesystem is out of nodes, so I suspect that somewhere there are a lot of files/directories which are just garbage, and I want to find them.

我被告知文件系统没有节点,所以我怀疑某处有很多文件/目录只是垃圾,我想找到它们。

I’ve tried running this:

我试过这个:

$ find /home/user -type d -print | wc -l

to find specific directories.

找到特定的目录。

1 个解决方案

#1


13  

starting from the current directory, you could try

从当前目录开始,你可以试试

find . -type d | cut -d/ -f 2 | uniq -c

This will list all directories starting from the current one, split each line by the character "/", select field number "2" (each line starts with "./", so your first field would be ".") and then only outputs unique lines, and a count how often this unique line appears (-c parameter).

这将列出从当前目录开始的所有目录,用字符“/”分隔每一行,选择字段编号“2”(每行以“./”开头,因此您的第一个字段将是“。”)然后仅输出唯一的行,并计算此唯一行出现的频率(-c参数)。

You could also add an "sort -g" at the end.

您还可以在末尾添加“sort -g”。

#1


13  

starting from the current directory, you could try

从当前目录开始,你可以试试

find . -type d | cut -d/ -f 2 | uniq -c

This will list all directories starting from the current one, split each line by the character "/", select field number "2" (each line starts with "./", so your first field would be ".") and then only outputs unique lines, and a count how often this unique line appears (-c parameter).

这将列出从当前目录开始的所有目录,用字符“/”分隔每一行,选择字段编号“2”(每行以“./”开头,因此您的第一个字段将是“。”)然后仅输出唯一的行,并计算此唯一行出现的频率(-c参数)。

You could also add an "sort -g" at the end.

您还可以在末尾添加“sort -g”。