0

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 ?

2
  • 3
    What is your research effort? How do you do it with root? Have you tried the same command without root? Usually df does not require root access. Commented Apr 19, 2021 at 14:31
  • Can you clarify what you mean by "disk free space"? There is more than one kind of free space: partition space, file system space, etc. If you only want to know "is there enough disk space in my /home/username directory to download an ISO image file", try "df -h /home/username" (the -h option tells df to output "human readable" size units).
    – C. M.
    Commented Apr 21, 2021 at 10:39

1 Answer 1

1

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:

enter image description here

UDisks doesn't have a simple way to display this. You'd need to use its DBus API and calculate the free space yourself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .