df -h
输出:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/system-root 55G 3.1G 49G 6% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 488M 152M 301M 34% /boot
/dev/mapper/system-home 240M 2.3M 221M 1% /home
预期产量:
它应该跳过第一行并排序第5列,第5列中的每个元素都应该作为参数传递给df -h命令。例如:df -h /boot
为
/dev/sda1 488M 152M 301M 34% /boot
这是我到目前为止编写的代码
import subprocess
from subprocess import Popen, STDOUT, PIPE
w = subprocess.check_output(["df", "-h"])
for line in w.splitlines():
field = line.split()
q = re.sub('/home', '', field[5])
print q
# r = q.split()
s = subprocess.Popen(["df", "-h", q], shell=True, stdin=PIPE, stdout=PIPE,
stderr=PIPE)
stdout, stderr = s.communicate()
print stdout