How can I get the number of inodes used by files in a given directory tree? Important: including hidden directories under it, like .git

migrated from serverfault.com May 24 '13 at 15:24

This question came from our site for system and network administrators.

  • @ptman: thanks, but my problem is mostly about the "Important" warning... – greg0ire May 24 '13 at 10:11
  • And why would find . exclude those? – ptman May 24 '13 at 10:13
  • Woops, turns out it does not, you're right – greg0ire May 24 '13 at 10:18

As found on How do I count all the files recursively through directories

find . -printf '%i\n' | sort -u | wc -l

Or if you don't have GNU find and need a portable version:

find . -exec ls -id '{}' \; | awk '{print $1}' | sort -u | wc -l
  • solaris wont like that because of the multiple spaces before the inode number, you also need to uniquely sort before counting lines, as im sure you know. find . -exec ls -id {} \; |awk '{print $1}' | sort -u | wc -l – Sirch May 24 '13 at 11:51
  • @Sirch you are of course correct. Fixed. – ptman May 24 '13 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.