I'd like to know if there is a way to get free space disk of a unix (debian) system without root (sudo) and if possible in only one command ?
1 Answer
Depends on what "free space" are you trying to get.
df
provides information about free space for mounted filesystems and it doesn't require root:
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 717M 0 717M 0% /dev
tmpfs 737M 0 737M 0% /dev/shm
tmpfs 295M 1,3M 294M 1% /run
/dev/mapper/fedora-root 17G 11G 5,4G 67% /
tmpfs 737M 9,5M 727M 2% /tmp
/dev/sda1 976M 285M 625M 32% /boot
If you want to know how much free/unallocated space is on each disk (space not occupied by partitions), you need to use tools like parted
or fdisk
and you need root privileges for that. lsblk
can help, but it doesn't print free space:
$ lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 1G 0 disk
├─sdb1 8:17 0 100M 0 part
├─sdb2 8:18 0 512B 0 part
└─sdb3 8:19 0 100M 0 part
But you can assume from its output that sdb
here has approximately 800 MiB of free space for a new partition.
You can get better picture with UDisks, which also has information about partition layout, GNOME Disks uses this data to display free space on disks:
UDisks doesn't have a simple way to display this. You'd need to use its DBus API and calculate the free space yourself.
df
does not require root access.