• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to find particular file in which partition of hard disk in linux?

Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to find out particular files details in Linux(Centos) by java program.
I create one text file & stored on Desktop.
Now i want to get info like at which partition of hard disk it stored?
at what block it used? exact location in terms of hdd internal?

I know few commands which show me hdd details like
df -l
fdisk -l

but that not sufficient?
Any idea/clue/help?
Posts: 69847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But fdisk and mount won't show you the location of individual files; at best, fdisk will show the sizes of the partitions.
I don't know that you can actually get at the locations of file from the file tables.
Saloon Keeper
Posts: 22273
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Linux runs data management through multiple layers of abstractions, some of which are plug-replaceable. The absolute sector address of a particular byte in a particular file can be calculated, but unless you're writing a low-level disk utility, it's not usually worth the trouble.

For example:

the "df" command issued using the directory of the file will tell you what partition the file is located in. That may be a raw partition (/dev/sda1), an LVM Logical Volume (/dev/VolGroup0/LogVol00), or even a network share ("host1:/export/myfiles"), although in the case of a network share, you might was well give up right now.

For a raw partition, the classical next step would be to get the sector extent which used to be something that the fdisk utility could display, but the old partition tables are on their way out.

For LVM, a logical volume consists of one or more transparent blocks of sectors which may be moved around at need. You'd have to use the LVM utilities to get the logical and physical sector addresses, then get the extents of whatever raw partition the LVM Physical Volume was working out of. And that's not even counting the mapper, which also gets into the act.

Nor did I allow for how different filesystems map sectors, RAID, or other considerations.

Or how the disk hardware itself may remap things owing to stuff like badblock remapping.

Virtually none of the services that you need to ferret out all this information is available to straight Java code, since it's extremely system-dependent and thus doesn't all under Java's "write once/run anywhere" constraints.
Posts: 3149
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The closest thing I have used is Sigar, but it doesn't go go down to the metal like what you are looking for.
    Bookmark Topic Watch Topic
  • New Topic