why doesn't unix's du(1) command support -i for inode measurement?
Is it simply because going from filenames to inode numbers is difficult in userspace, and you can't read inodes from there?
Solution 1:
GNU coreutils' implementation of du(1) will support the --inodes option with the next release (>8.21) ... I've just pushed the patch to upstream Git (http://git.sv.gnu.org/cgit/coreutils.git/commit/?id=333dc83d). See http://lists.gnu.org/archive/html/coreutils/2013-07/msg00087.html
Solution 2:
Use df
, not du
!
du
stands for "disk usage". It is df
which stands for "disk free" and will check the filesystem proper. Including inode usage with the -i
option!
Otherwise, just do:
find thedirectory -exec ls -di {} \;|awk '{print $1}'|sort|uniq|wc -c
or similar
Solution 3:
This won't give an exact answer - in particular it equates directory entries with files, and so double counts hard links, as well as having issues with line feeds in file/directory names - but is probably "good enough" for most purposes:
find /data | awk -F/ '{s=""; for (i=2; i<NF;i++) {s = s"/"$i; print s}}' | sort | uniq -c | sort -n
That sorts by inode (sic) count. if you want a traditional directory-sorted order:
find /data | awk -F/ '{s=""; for (i=2; i<NF;i++) {s = s"/"$i; print s}}' | sort | uniq -c | sort -k2
Most commonly I want something like this when a drive is running out of inodes and I want to know where they're being used. For that purpose, some minor inaccuracies are usually not a big deal.
It should be possible to use "find -ls" and parse the inode numbers in the listing to eliminate duplicates, if you want something more accurate.