7

Is it simply because going from filenames to inode numbers is difficult in userspace, and you can't read inodes from there?

nick black
  • 171
  • 1
  • 5
  • The answer is twofold, I think. It's not available in general because, as suggested, a normal user can't go reading inodes arbitrarily. It's not available as a tool requiring root access because there's no easy, reliable way to go from filenames to inode numbers outside the kernel. –  Dec 14 '11 at 09:03
  • Better off on unix.stackexchange.com – Chris J Dec 14 '11 at 09:04

3 Answers3

6

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

Berny
  • 61
  • 1
  • 1
2

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.

Ronny Cook
  • 21
  • 1
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

fge
  • 593
  • 1
  • 3
  • 9
  • No, I want a hierarchal summary of the inode usage from a given root. I know what tool I'm talking about. –  Dec 14 '11 at 09:00
  • but why, why do you think he wants to measure file system disk space usage? – Oleg Mikheev Dec 14 '11 at 09:02
  • `find|wc -l`, then... Of course you'll need to account for files with multiple links. But your question doesn't really make any sense. –  Dec 14 '11 at 09:03
  • @Oleg, I didn't say this at all. `df` has a `-i` option. –  Dec 14 '11 at 09:04