77

This question already has an answer here:

I am using Ubuntu 12.04 LTS and I was wondering if there is a command that can tell the space used in a partition using the terminal. Like I want to use the su command to change to a user called admin (it is named admin). So I typed :

su admin

Entered the password

Now I want to see the disk space used in this partition. So.... Is there is a command fot that?

marked as duplicate by Eric Carvalho, David Foerster, user364819, A.B., chaos Oct 21 '15 at 16:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This thread is locked but I just wanted to say that ncdu is fantastic for a job like this: unix.stackexchange.com/a/3964/13779 – Gerry May 22 '16 at 16:34
  • Can someone remove the duplicate tag? This question is for the terminal. – Diogo Gomes Dec 31 '18 at 3:47
  • lsblk | grep sda should help. – ImtiazeA Mar 25 at 5:36
130

The su command is completely irrelevant. The disk usage is the same for all users. Anyway, some relevant commands and their output on my system are:

terdon@oregano ~ $ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda7              68G   23G   43G  35% /
udev                   10M     0   10M   0% /dev
tmpfs                 800M  1.6M  798M   1% /run
tmpfs                 5.0M     0  5.0M   0% /run/lock
tmpfs                 3.2G   12M  3.2G   1% /run/shm
/dev/sda6             290G  256G   20G  94% /home
tmpfs                 3.2G  992K  3.2G   1% /tmp
none                  4.0K     0  4.0K   0% /sys/fs/cgroup
/dev/sdc1             466G  379G   88G  82% /media/terdon/Iomega_HDD

For a specific partition:

terdon@oregano ~ $ df -h /dev/sda7
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda7              68G   23G   43G  35% /

Alternatively, though this only lists the size, not the %used:

terdon@oregano ~ $ lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0  39.2M  0 part 
├─sda2   8:2    0  14.7G  0 part 
├─sda3   8:3    0  78.1G  0 part 
├─sda4   8:4    0     1K  0 part 
├─sda5   8:5    0     2G  0 part 
├─sda6   8:6    0 294.4G  0 part /home
├─sda7   8:7    0  68.7G  0 part /
└─sda8   8:8    0   7.8G  0 part [SWAP]
sdc      8:32   0 465.8G  0 disk 
└─sdc1   8:33   0 465.8G  0 part /media/terdon/Iomega_HDD
sr0     11:0    1  1024M  0 rom  

Conversely, you can use the du command to print directory size which will give you the disk usage of a partition if you run it on a partition's mountpoint: du -xsch /home for example. The -x option will "skip directories on different file systems," which is helpful if you have other mount points nested below the partition's mount point (typically /).

  • 4
    -h stands for human which makes it readable by us humans, otherwise it will be in bytes ^^ – Mr.Lee Mar 11 '14 at 18:24
  • +1 for the du -xsch /home example; especially -x – R. Oosterholt Mar 16 '17 at 11:15
30

You can use df -Th to get the used space of partitions:

$ df -Th

Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda9      ext4       22G   16G  4.8G  77% /
none           tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
udev           devtmpfs  1.5G  4.0K  1.5G   1% /dev
tmpfs          tmpfs     297M  1.4M  295M   1% /run
none           tmpfs     5.0M  4.0K  5.0M   1% /run/lock
none           tmpfs     1.5G  616K  1.5G   1% /run/shm
none           tmpfs     100M   68K  100M   1% /run/user
/dev/sda5      fuseblk    53G   34G   19G  65% /media/Songs
/dev/sda7      fuseblk   103G   90G   14G  88% /media/Data
/dev/sda6      fuseblk    69G   34G   35G  50% /media/Movies
/dev/sda1      fuseblk    49G   36G   14G  72% /media/guru/0C64A7F864A7E326

You can also provide it with a specific partition if you want to view disk utilization of only that partition:

$ df -Th /dev/sda9

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda9      ext4   22G   16G  4.8G  77% /

You can also use pydf or discus to get better representation in terminal. You need to install these if you want to use it. Type:

sudo apt-get install pydf in terminal to install pydf.

$ pydf  
Filesystem Size Used Avail Use%                                      Mounted on                  
/dev/sda9   22G  16G 4893M 72.7 [#########################.........] /                           
/dev/sda7  103G  90G   13G 87.2 [##############################....] /media/Data                 
/dev/sda6   69G  34G   35G 49.3 [#################.................] /media/Movies               
/dev/sda5   53G  34G   19G 64.5 [######################............] /media/Songs                
/dev/sda1   49G  35G   14G 71.9 [########################..........] /media/guru/0C64A7F864A7E326
  • 1
    pydf is much easier to read. 6/7 of the df -Th entries are confusing garbage. – mpen Jan 5 '17 at 2:09
9

You can easily check disk space status with df -h.

Sometimes you might end up accidentally filling your hard disk via some automated processes you've set up. When that happened to me I needed to find where most of my disk space went. The following command was helpful for that task:

$ cd /
$ sudo du -sh ./*

This gives a list of files and folders in the current directory as well as the size of each one. If a directory is larger than it should be, cd to that directory and run sudo du -sh ./* again. Repeat until you've found what is using up most of your disk space.

  • This is helpful – U2m Dec 26 '17 at 9:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.