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.
You could use the "debugfs" tool to view file info on the command line or interactivley. either use:
or
for example:
A simple way to get the list of blocks (without having to read from the partition like in the
debugfs
answers) is to use theFIBMAP
ioctl. I do not know of any command to do so, but it is very simple to write one; a quick Google search gave me an example of FIBMAP use, which does exactly what you want. One advantage is that it will work on any filesystem which supports thebmap
operation, not just ext3.A newer (and more efficient) alternative is the
FIEMAP
ioctl, which can also return detailed information about extents (useful for ext4).I will not work on zfs, but will on ext4, btrfs, (v)fat, etc
man 8 hdparm
:Look at the syntax for "debugfs", and specifically the "stat" command. That will show you a list of the data blocks used by a file. You can pass parameters to "debugfs" with the "-f" argument to call it from a script.
At least on some linux machines... "ls -s" might provide what you're looking for.
Edit: my bad, I see that you're looking for a list of the blocks themselves, not a count of them.