108 reputation
4
bio website antonyh.co.uk
location London, UK
age
visits member for 1 year, 6 months
seen Jul 18 at 11:04

Feb
26
awarded  Supporter
Feb
24
comment How to find what device a file is on (and use that in a script)?
my apologies; this isn't mentioned in the man page, only the 512-byteness of the output for -P is in the documentation.
Feb
23
awarded  Commentator
Feb
23
awarded  Scholar
Feb
23
accepted How to find what device a file is on (and use that in a script)?
Feb
23
comment How to find what device a file is on (and use that in a script)?
All good; I love that there's so many ways to do this, and it's interesting to see how the time changes between awk, mawk, and gawk. What a great reference for this, thanks for taking the time to benchmark them too!
Feb
23
comment How to find what device a file is on (and use that in a script)?
On OSX the -P option forces 512-byte blocks and has nothing to do with formatting. stat -f %Sdr . gives me the device name without the /dev/ prefix so it's close but I don't want to make assumptions that the device isn't in a sub-directory.
Feb
22
awarded  Student
Feb
22
comment How to find what device a file is on (and use that in a script)?
@manatwork thanks, I like this best - simple to read and fast. Please post it up as an answer so I can accept it.
Feb
22
comment How to find what device a file is on (and use that in a script)?
Quite right, here's my timings; time for i in {1..500}; do df . | sed -n '2{s/ .*$//;p;}'; done real 0m1.587s user 0m0.472s sys 0m1.180s time for i in {1..500}; do df . | sed '2!d' | awk '{print $1}'; done real 0m2.484s user 0m0.722s sys 0m1.833s time for i in {1..500}; do df . | tail -1 | awk '{print $1}'; done real 0m2.267s user 0m0.672s sys 0m1.701s I just need to work out how to do this one more way then I'll be happy. awk?
Feb
22
comment How to find what device a file is on (and use that in a script)?
stat -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.
Feb
22
revised How to find what device a file is on (and use that in a script)?
add sed and awk tags
Feb
22
comment How to find what device a file is on (and use that in a script)?
Thanks @jofel. -- @manatwork how would you do this with just awk? @peterph has already given an answer with just sed.
Feb
22
comment How to find what device a file is on (and use that in a script)?
BSD sed, as found on OSX 10.7 - df . | sed -n '2{s/ .*$//;p;}' - this works
Feb
22
comment How to find what device a file is on (and use that in a script)?
what do the options on sed mean? I can guess that 2 means second line, but the rest is cryptic to me.
Feb
22
comment How to find what device a file is on (and use that in a script)?
Nice, this works. I'm running it on 10'000s of files, so I will have to see what the performance is like VS just one pipe
Feb
22
comment How to find what device a file is on (and use that in a script)?
This didn't work for me: sed: 1: "2{s/ .*$//;p}": extra characters at the end of p command
Feb
22
asked How to find what device a file is on (and use that in a script)?