Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Java - Exclude Linux Drives

frank.anelliaNov 28 2017 — edited Nov 29 2017

Hello,

I have the following code that reports on mounted filesystems from /etc/mstab in Linux:

import java.io.IOException;

import java.nio.file.FileStore;

import java.nio.file.FileSystems;

public class linuxMounts {

    public static void main(String[] args) throws IOException {

      for (FileStore store : FileSystems.getDefault().getFileStores()) {

         long total = store.getTotalSpace() / 1024;

         long used = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024;

         long avail = store.getUsableSpace() / 1024;

         System.out.format("%-20s %12d %12d %12d%n", store, total, used, avail);

      }

   }

}

The output is as follows:

/ (/dev/mapper/rootvg-rootlv)     15350768      3111056     11453280

/proc (proc)                    0            0            0

/sys (sysfs)                    0            0            0

/dev/pts (devpts)               0            0            0

/dev/shm (tmpfs)          8160264       649396      7510868

/boot (/dev/sda1)          243823       107889       123134

/home (/dev/mapper/rootvg-homelv)      5029504      1222208      3545152

/opt (/dev/mapper/rootvg-optlv)      3997376       628816      3158848

/tmp (/dev/mapper/rootvg-tmplv)      3997376       205540      3582124

/usr (/dev/mapper/rootvg-usrlv)     15350768      5281180      9283156

/var (/dev/mapper/rootvg-varlv)      3997376      2841840       945824

/var/crash (/dev/mapper/rootvg-crashlv)     12254384        30704     11594536

/u01 (/dev/mapper/mpathgp1)    103079868     83741420     14098936

/backups (/dev/mapper/mpathip1)    103079868     68240572     29596488

/proc/sys/fs/binfmt_misc (none)            0            0            0

/dev/oracleasm (oracleasmfs)            0            0            0

/var/lib/nfs/rpc_pipefs (sunrpc)            0            0            0

I'd like to exclude most of these filesystem and keep only a certain few like '/u01' and '/backups'.  I'd also only like to return '/backups' instead of the full path.

I'm new to Java programming and I've been using Google for several days without any luck.

Thanks in advanced for your help!

Frank

This post has been answered by mNem on Nov 29 2017
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 27 2017
Added on Nov 28 2017
22 comments
636 views