7

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

2
  • 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.
    – nick black
    Dec 14, 2011 at 9:03
  • Better off on unix.stackexchange.com
    – Callie J
    Dec 14, 2011 at 9:04

3 Answers 3

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

1
  • Should that be > 8.21 or ≥ 8.21?
    – gerrit
    Aug 16, 2018 at 11:06
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

4
  • No, I want a hierarchal summary of the inode usage from a given root. I know what tool I'm talking about.
    – nick black
    Dec 14, 2011 at 9:00
  • but why, why do you think he wants to measure file system disk space usage? Dec 14, 2011 at 9: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.
    – fge
    Dec 14, 2011 at 9:03
  • @Oleg, I didn't say this at all. df has a -i option.
    – fge
    Dec 14, 2011 at 9:04
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .