Get available space on mounted device with folder with whitespaces using bash

时光怂恿深爱的人放手 提交于 2021-01-29 10:50:58

问题


I try to get Available space on mounted disk:

df /tmp/mount/0dfShksftN | tail -1 | awk '{print $4}' 

It works fine but not in cases when Filesystem param has folder name with spaces.

I found solution for getting Filesystem and Mount point values in this case:

df -P "/mnt/MOUNT WITH SPACES/path/to/file/filename.txt" | awk 'BEGIN {FS="[ ]*[0-9]+%?[ ]+"}; NR==2 {print $NF}'

But can't find solution for Available field value. I could take the entire string and parse by myself but maybe there is a way to do this using bash,


回答1:


You can use --output filter of df command.

df "<file-system>" --output=avail
    Avail
868215420

For your original approach, you may need to consider counting column backward.

From the man page of df(1):

FIELD_LIST is a comma-separated list of columns to be included. Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).



来源:https://stackoverflow.com/questions/65494333/get-available-space-on-mounted-device-with-folder-with-whitespaces-using-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!