I have an UBUNTU installation USB disk.
The disk name is "UBUNTU 22_0" and will be mounted on "/run/media/UBUNTU 22_0-sda1".
There is a space on it so the command "df | grep /dev/sda | awk ‘{ print $6 }’" is not work.
root@host:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 2972456 1629696 1169092 59% /
devtmpfs 733972 4 733968 1% /dev
tmpfs 981396 0 981396 0% /dev/shm
tmpfs 392560 9544 383016 3% /run
tmpfs 4096 0 4096 0% /sys/fs/cgroup
tmpfs 981400 20 981380 1% /tmp
tmpfs 981396 232 981164 1% /var/volatile
tmpfs 196276 0 196276 0% /run/user/0
/dev/mmcblk2p2 65390 0 65390 0% /run/media/fake-mmcblk2p2
/dev/mmcblk1p1 122078208 3231488 118846720 3% /run/media/mmcblk1p1
/dev/mmcblk2p1 65390 37516 27874 58% /run/media/boot-mmcblk2p1
/dev/mmcblk2p4 4129072 1084 3894212 1% /run/media/data-mmcblk2p4
/dev/sda1 3992256 3833984 158272 97% /run/media/UBUNTU 22_0-sda1
root@host:~# df | grep /dev/sda | awk '{ print $6 }'
/run/media/UBUNTU
2
Answers
Do it by character position instead of field number.
Also, there’s no need to use
grep
whenawk
can match the first field itself.Any
df
should let you specify which filesystem you want to see, and with GNUdf
, you can format the output: