Tuesday, February 6, 2024

[SOLVED] how to check whether two files in same physical harddisk in linux bash or python?

Issue

I'm optimizing an I/O intensive Linux program. So is there any way to know whether two given files/folders path are in same hard disk?


Solution

If, by "same physical harddisk" you mean same fileystem, then you can use the stat command to get the device ID:

$ stat -c '%D' filename
$ fd03

If the device IDs match, they're in the same filesystem.

To actually determine the physical disk the file is on, you'd have to know the filesystem in use (some filesystems can span multiple disks), and even the "device" itself may be mapped to more than one actual physical disk by a volume manager such as LVM or a RAID controller.



Answered By - Andrew Henle
Answer Checked By - Gilberto Lyons (WPSolving Admin)