On Linux, how to find a search directory with most subdirectories or files?

How can I find the directory with the most files / subdirectories in it in the system? Obviously, the smart answer is / , but that is not what I am looking for.

I was told that there are no nodes in the file system, so I suspect there are a lot of files / directories somewhere that are just rubbish and I want to find them.

Ive tried to run this:

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

to find specific directories.

+6
source share
1 answer

starting from the current directory, you can try

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

All directories are listed here, starting from the current one, separate each line with the β€œ/” symbol, select the field number β€œ2” (each line starts with β€œ./”, so your first field will be β€œ.”) And then displays only unique lines and counts how often this unique string appears (-c option).

You can also add "sort -g" at the end.

+11
source

Source: https://habr.com/ru/post/917904/


All Articles