Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

up vote 8 down vote accepted

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
share|improve this answer

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.

share|improve this answer

A simple way to get the list of blocks (without having to read from the partition like in the debugfs answers) is to use the FIBMAP 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 the bmap 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).

share|improve this answer

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.

share|improve this answer
    
-s shows the size of the file in blocks -- i want an actual list of the block numbers. –  mike Jun 22 '09 at 18:10

e2fsck -b 32768 /dev/hda1 i feel u can try this out or if u looking more docx on the same u can check following

http://www.linux-tutorial.info/modules.php?name=MContent&pageid=97

share|improve this answer
    
That command runs a filesystem check, taking 32768 as a backup superblock. That isn't what he asked for. –  James Broadhead Dec 11 '11 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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