How to Find Files and Print Inode Numbers in Ubuntu (find -printf)

The Data Structure Audit

When auditing a Linux filesystem for corrupted data or tracing complex hard links, simply knowing the file’s name or path is often insufficient. You need to know the exact physical address of the file’s data blocks on the hard drive, which is represented by its index node (inode) number. While you can use ls -i to view the inode of a specific file, extracting a massive, formatted list of inodes for thousands of files requires advanced string formatting directly within the search engine.

Using the find Command with -printf

The Linux find command utilizes the highly flexible -printf flag to precisely dictate how the output of the search results is formatted, allowing you to extract raw system metadata.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To scan the /var/log/ directory and print a clean list showing the inode number followed by the file path, type the following command exactly:
  3. find /var/log/ -type f -printf "%i - %p\n"
  4. Press Enter.

Formatting Forensics

The -printf string relies on specialized format directives. %i extracts the raw inode number of the matched file. The hyphen and spaces are literal characters that will be printed exactly as typed. %p extracts the full file path. Finally, \n acts as a carriage return, forcing a new line for the next result (without it, all results would print on a single continuous, unreadable line). This command is an absolute necessity for system administrators building automated filesystem health reports or writing bash scripts that must directly manipulate hard links via their numerical data addresses.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.