With GNU coreutils (Linux, Cygwin) since version 8.22, you can use du --inodes
, as pointed out by lcd047.
If you don't have recent GNU coreutils, and there are no hard links in the tree or you don't care if they're counted once per link, you can get the same numbers by filtering the output of find
. If you want the equivalent of du -s
, i.e. only toplevel directories, then all you need is to count the number of lines with each toplevel directory name. Assuming that there are no newlines in file names and that you only want non-dot directories in the current directory:
find */ | sed 's!/.*!!' | uniq -c
If you want to show output for all directories, with the count for each directory including its subdirectories, you need to perform some arithmetic.
find . -depth | awk '{
# Count the current depth in the directory tree
slashes = $0; gsub("[^/]", "", slashes); current_depth = length(slashes);
# Zero out counts for directories we exited
for (i = previous_depth; i <= current_depth; i++) counts[i] = 0;
# Count 1 for us and all our parents
for (i = 0; i <= current_depth; i++) ++counts[i];
# We don´t know which are regular files and which are directories.
# Non-directories will have a count of 1, and directories with a
# count of 1 are boring, so print only counts above 1.
if (counts[current_depth] > 1) printf "%d\t%s\n", counts[current_depth], $0;
# Get ready for the next round
previous_depth = current_depth;
}'
find dir/ -xdev | wc -l
will give you the number of inodes indir/
. You could probably use this with the-exec
option offind
to run this command for each directory.du -s --inodes
--inodes
is not yet present in GNU coreutils 8.4 (for example, RH/CentOS/SL 6.6).du --version
-du (GNU coreutils) 8.23
lsof
and counting the processes with many occurences of file descriptors... absolutely not guaranteed (the program most likely only do them one by one...) but this may help to catch a "massively creating files in parralel" nasty program? ) actually, for those ones, top and similar programs can also help find who is massively using io)