Determine Device for a File
Solution 1:
df /path/to/file | sed -n 2p | cut -d ' ' -f 1
will give you the device the file is on. To combine this directly with diskutil info
use
diskutil info $(df /path/to/file | sed -n 2p | cut -d ' ' -f 1)
Solution 2:
The easiest way to determine the device that contains a file is to use df
. For example:
$ df /Users/mj/bin/imgls
Filesystem 1K-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1s1 488347692 418217076 38565452 92% 3141515 9223372036851634292 0% /
You can use cut
if you just want the device (I used tail
as a crude way to remove the df
header).
$ df /Users/mj/bin/imgls | tail -1 | cut -d ' ' -f 1
/dev/disk1s1