MacOS – Determine Device for a File

bashmacosterminal

In a shell script, I need to determine the device for a file, subsequent use with diskutil, eg…

# ??? Assign device to FileDevice, based on full path.
diskutil info $FileDevice

Best Answer

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)