Since I'm having performance problems with rsnapshot, I'd like to identify directories with great number of files recursively. I think the problem is not the size of the files, but the file count in particular subdirectories, because the generations (daily.0, daily.1, ...) are not volatile and only have few changes compared to the total number of files.
Unix command du
would be exactly what I want, if it returned only the file count and not the sum of file sizes.
I already have a bash script which outputs the file count of all direct subdirectories (recursing into subdirectories), but it's cumbersome to use, because I have to dig deeper and deeper and always have to wait.
Found also a script digging deeply, but not summing up file count of subdirectories. It shows only the number of files in this directory, not from its children.
Doesn't have to be a shell script - I'm open to other scripting languages like Ruby, Python, Perl, JavaScript, ...
Example:
dir1/
file1
subdir1/
file2, file3, file4, file5
subdir2/
file6, file7, file8
subdir3/
file9
dir2/
fileA, fileB
Desired output (listing subdirectories and sum up to top):
4 dir1/subdir1
1 dir1/subdir2/subdir3
4 dir1/subdir2
9 dir1/
2 dir2/
What I don't want (only listing totals):
9 dir1/
2 dir2/
and not (only listing file count of .
directory):
4 dir1/subdir1
1 dir1/subdir2/subdir3
3 dir1/subdir2
1 dir1/
2 dir2/
du --inodes
doesn't work. The script with awk didn't work (probably I'm missing some bash knowledge). Next: Many user won't find your answer with a similar question or problem like mine. Of course I've heard of inodes, but who exactly knows the subtile differences between inodes and files? => IMO my question is not a duplicate from many users point of view. – hgoebl Aug 02 '15 at 19:45awk: cmd. line:8: ^ syntax error
. Maybe I should have added line continuation characters\
at the end of each line? But you may have a look at the answers. They are also brilliant. Unbelievable what can be expressed in one line... – hgoebl Aug 02 '15 at 19:54gdu --inodes
instead ofdu
:gdu --inodes | sort -n
- seems to work usefully. Requiresbrew install coreutils
IIRC. – KarolDepka Jan 04 '22 at 20:40