I want to find out what device my file is on so that I can use it in a script. I can get this far:
$ df .
Filesystem 512-blocks Used Available Capacity Mounted on
/dev/disk0s2 498438976 294369520 203557456 60% /
but this output feels too clumsy; is there a better way than parsing this to get the first 'word' of the second line?
What I really need is something like this so I can pipe it to the next command:
$ somecommand .
/dev/disk0s2
How can I achieve this, preferably without resorting to string hacking the 'df' output?
df
output is not difficult:df . | tail -1 | cut -f 1 -d " "
But maybe there are better solutions. – jofel Feb 22 '13 at 12:35stat
, which gives a device field, but you'll have to translate that back. May be much faster though, especially ifdf
is taking forever to get usage over, e.g., NFS. – derobert Feb 22 '13 at 13:37stat -f "%Sdf" .
seems quicker - it decreased the time from 1.8s to 1.7 over 500 iterations. I have no network concerns, but this is a top tip, thanks. – antonyh Feb 22 '13 at 14:45