in reply to get the size of a special device (drive)

I need my script to get the size (Preferably in bytes) of a hard drive, I tried this: my $Size = (-s "/dev/sda4"); but it always sets $Size to 0.

Since this seems very OS-specific it may be sensible to use OS-specific tools. Anyway a module like Sys::Filesystem seems like a good start. I found it with a few seconds' CPAN search for Linux device. Other searches may return more appropriate results for you.

  • Comment on Re: get the size of a special device (drive)

Replies are listed 'Best First'.
Re^2: get the size of a special device (drive)
by exodist (Monk) on May 30, 2007 at 21:26 UTC
    Unfortunately what I am writing is a filesystem... But I went browsing through /proc and found /proc/partitions, when I cat that it shows partitions and sizes in blocks (1024 bytes each I believe) Is this standard and reliable from linux system to linux system?
      Unfortunately what I am writing is a filesystem... But I went browsing through /proc and found /proc/partitions, when I cat that it shows partitions and sizes in blocks (1024 bytes each I believe) Is this standard and reliable from linux system to linux system?

      I think something changed between 2.4 and 2.6, but I wouldn't take my own word as the ultimate Truth™ as I'm far from being an expert...