LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-26-2008, 06:35 PM   #1
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Rep: Reputation: 49
How to find physical location of a file on the HDD?


How would I find which physical sectors on the HDD a file occupies? I noticed that when I do:
Code:
ls -i
It will give me the index number of the file, but then could I use that to find where the file is on the HDD? Thanks in advance.
 
Old 10-26-2008, 06:51 PM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
What is the location of the file? There is inode (file metadata), extra xattr nodes (usually none), and data blocks. If your file is rather big (I think no FS has default block size of more than 16*1024 bytes on a HDD less than 1TB), it will have to be split. With some luck the fragments will be one near other on the disk, but there is some additional information in every block (like a pointer to the next block of the file).

I think GRUB is a good place to see FS read-only implementations
 
Old 01-18-2009, 10:14 AM   #3
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Original Poster
Rep: Reputation: 49
In case anyone else is interested, I did find a solution to my question, so I thought I would post it. It turns out you can use the "filefrag" command to find the physical location of a file:
Code:
filefrag -v myfile.txt
It gives an output like:
Code:
Checking myfile.txt
Filesystem type is: ef53
Filesystem cylinder groups is approximately 115
Blocksize of file myfile.txt is 4096
File size of myfile.txt is 121460 (30 blocks)
First block: 2209841
Last block: 2212769
Discontinuity: Block 7 is at 2211636 (was 2209847)
Discontinuity: Block 11 is at 2211645 (was 2211639)
Discontinuity: Block 13 is at 2211925 (was 2211647)
Discontinuity: Block 14 is at 2211931 (was 2211925)
Discontinuity: Block 19 is at 2211966 (was 2211935)
Discontinuity: Block 26 is at 2212669 (was 2211972)
Discontinuity: Block 29 is at 2212769 (was 2212671)
myfile.txt: 8 extents found, perfection would be 1 extent
4096 * 2209841 = 9,051,508,736, so that means the file starts about 9 GB into the partition.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Logical disks and physical location on Sparc dazdaz Solaris / OpenSolaris 2 09-11-2007 09:52 AM
find the exact location of a running exec file cahdecah General 4 08-16-2007 10:53 AM
WHat is the physical path or location of the trash folder? ImOk Linux - Software 3 10-23-2006 12:39 PM
Changing physical location of directories Linus VanPelt Mandriva 2 02-23-2004 07:42 AM
vmware and physical HDD keevitaja Linux - General 7 02-17-2003 08:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration