Pav*_*ath 3 c linux filesystems directory mount
例如,示例df
命令输出是
Filesystem MB blocks Free %Used Iused %Iused Mounted on
/dev/hd4 512.00 322.96 37% 4842 7% /
/dev/hd2 4096.00 717.96 83% 68173 29% /usr
/dev/hd9var 1024.00 670.96 35% 6385 4% /var
/dev/hd3 5120.00 0.39 100% 158 10% /tmp
Run Code Online (Sandbox Code Playgroud)
现在,如果我指定类似/tmp/dummy.txt
我应该能够得到/dev/hd3
或只是hd3
.
编辑:感谢 torek 的回答。但是探查/proc
会变得非常乏味。谁能建议我一些可以在内部执行相同操作的系统调用?
小智 5
df `pwd`
Run Code Online (Sandbox Code Playgroud)
...超级简单,有效,还告诉你有多少空间......
[stackuser@rhel62 ~]$ pwd
/home/stackuser
[stackuser@rhel62 ~]$ df `pwd`
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 250056240 196130640 41223408 83% /
[stackuser@rhel62 ~]$ cd isos
[stackuser@rhel62 isos]$ pwd
/home/stackuser/isos
[stackuser@rhel62 isos]$ df `pwd`
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 103216920 90417960 11750704 89% /mnt/sda5
[stackuser@rhel62 isos]$ df $(pwd)
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 103216920 90417960 11750704 89% /mnt/sda5
Run Code Online (Sandbox Code Playgroud)
...这首先是挂载点查询的可能原因。
请注意,这些是反引号,另一种(现代)方法提供对斜杠和扩展的进一步控制是df $(pwd)
. 已测试并正确遍历bash
, dash
, busybox
,上的符号链接zsh
。请注意,tcsh
不会喜欢$(...)
, 所以在 csh-variants 中坚持使用旧的反引号样式。
也有额外的交换机pwd
,并df
进一步享受。