HighLife
HighLife

Reputation: 4344

Checking Current File System with Perl

I need my perl script to check the file system type of the computer it's running on. What is the easiest way to do this? (on Linux)

Upvotes: 2

Views: 1907

Answers (3)

rmflow
rmflow

Reputation: 4795

There is a linux command df -T to determine filesystem

You can invoke it from your script and parse the output:

my $filesystem_info = `df -T`;

Upvotes: 3

Nemo
Nemo

Reputation: 71615

The only reliable way to do what you want is (a) decide which mount you are talking about and (b) find its entry in /proc/mounts.

On Linux, /proc/mounts lists all mounted file systems. The format of each line is "device mount-point fs-type mount-options'. It is human-readable; cat /proc/mounts and you should get the idea.

(Note that /etc/fstab only lists the file systems that get auto-mounted at boot time. That can be different than what is mounted at the time the script runs for all sorts of reasons, most notably automounters. /proc/mounts is what you want.)

Upvotes: 2

Doug
Doug

Reputation: 6442

You can try parsing the /etc/fstab file to find it out. Beware there might be multiple filesystems in this file, you have to pick the one you want.

Upvotes: 0

Related Questions