Linux – How to list a file’s data blocks on Linux

ext3filesystemslinuxunix

As I understand it, each file on a Unix-like operating system has an inode number (which can be viewed with "ls -i"), and each inode is a list of disk blocks that contain the actual data of a file.

Is there a Linux command which takes a filename as its argument and prints out the list of disk blocks that that file's inode points to?

P.S. The filesystem in question is ext3.

Best Answer

You could use the "debugfs" tool to view file info on the command line or interactivley. either use:

# debugfs /dev/<spartition>
# stat /path/to/file

or

# debugfs -R "stat /path/to/file" /dev/<partition>

for example:

# debugfs -R "stat /etc/passwd"  /dev/sda5
Inode: 435914   Type: regular    Mode:  0644   Flags: 0x0
Generation: 979004472    Version: 0x00000000
User:     0   Group:     0   Size: 1577
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 8
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x4a2d6f78 -- Mon Jun  8 23:07:20 2009
atime: 0x4a2d6f79 -- Mon Jun  8 23:07:21 2009
mtime: 0x4a2d6f78 -- Mon Jun  8 23:07:20 2009
Size of extra inode fields: 4
BLOCKS:
(0):1767438
TOTAL: 1