问题
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