[英]Checking Current File System with Perl
I need my perl script to check the file system type of the computer it's running on. 我需要我的perl脚本来检查正在运行的计算机的文件系统类型。 What is the easiest way to do this?
最简单的方法是什么? (on Linux)
(在Linux上)
There is a linux command df -T
to determine filesystem 有一个linux命令
df -T
来确定文件系统
You can invoke it from your script and parse the output: 您可以从脚本中调用它并解析输出:
my $filesystem_info = `df -T`;
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
. 唯一可靠的方法做你想要的是(A)决定哪些安装你所谈论的和(b)中找到其进入
/proc/mounts
。
On Linux, /proc/mounts
lists all mounted file systems. 在Linux上,
/proc/mounts
列出所有已挂载的文件系统。 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. 每行的格式是“ device mount-point fs-type mount-options”。它易于阅读;可以使用
cat /proc/mounts
理解。
(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.) (请注意,
/etc/fstab
只列出了获得自动安装在系统启动时的文件系统,这可以比安装在脚本种种原因运行的时间不同,最明显的是automounters。 /proc/mounts
是你想要什么。)
You can try parsing the /etc/fstab
file to find it out. 您可以尝试解析
/etc/fstab
文件以找到它。 Beware there might be multiple filesystems in this file, you have to pick the one you want. 请注意,此文件中可能有多个文件系统,您必须选择所需的文件系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.