Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The quick and dirty version: <code>df $file | awk 'NR == 2 {print $1}'</code>.</p> <p>Programmatically... well, there's a reason I started with the quick and dirty version. There's no portable way to programmatically get the list of mounted filesystems. (<code>getmntent()</code> gets <code>fstab</code> entries, which is not the same thing.) Moreover, you can't even parse the output of <code>mount(8)</code> reliably; on different Unixes, the mountpoint may be the first or the last item. The most portable way to do this ends up being... parsing <code>df</code> output (And even that is iffy, as you noticed with the partition number.). So you're right back to the quick and dirty shell solution anyway, unless you want to traverse <code>/dev</code> and look for block devices with matching <code>major(st_rdev)</code> (<code>major()</code> being from <code>sys/types.h</code>).</p> <p>If you restrict this to Linux, you can use <code>/proc/mounts</code> to get the list of mounted filesystems. Other specific Unixes can similarly be optimized: for example, on OS X and I think FreeBSD, you can use <code>sysctl()</code> on the <code>vfs</code> tree to get mountpoints. At worst you can find and use the appropriate header file to decipher whatever the mount table file is (and yes, even that varies: on Solaris it's <code>/etc/mnttab</code>, on many other systems it's <code>/etc/mtab</code>, some systems put it in <code>/var/run</code> instead of <code>/etc</code>, and on many Linuxes it's either nonexistent or a symlink to <code>/proc/mounts</code>). And its format is different on pretty much every Unix-like OS.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload